# Path: whirlwind/db/mongo.py
# class Mongo(Singleton):
#     
#     db = None
#     
#     def __init__(self):
#         self.connection = None
#     
#     '''
#         register a collection of mongokit model objects
#     '''
#     def register_models(self,models):
#         self.connection.register(models)
#     
#     '''
#         Accessor for ui specific database.
#     '''   
#     @property
#     def ui(self):
#         return self.connection[options.db_name]
#     
#     '''
#         Useage:
#         from whirlwind.db.mongo import Mongo
#         Mongo.create(host='host.com', port='23423', username='mongouser', password='password')
#     '''
#     @staticmethod
#     def create(**kwargs):
#         db = Mongo()
#         db.connection = Connection(kwargs['host'],kwargs['port'])
#         Mongo.db = db
#         if 'debug' in kwargs:
#             print Mongo.db.connection


import pymongo, datetime, logging, os
from whirlwind.db.mongo import Mongo
'''
class Log():
    instance = None
    
    def __init__(self,type='',log_file=''):
        if type == 'FILE' and log_file != '':
            #make sure we have a log directory
            dirname, filename = os.path.split(log_file)
            if not os.path.exists(dirname):
                os.makedirs(dirname)
            
            self.destination = 'FILE'
            self.file_logger = logging.getLogger('whirlwind')
            hdlr = logging.FileHandler(log_file)
            hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(user)s %(message)s %(extended_info)s'))
            self.file_logger.addHandler(hdlr)
            self.file_logger.setLevel(logging.DEBUG)
        else:
            assert Mongo.db != None, "Logger Exception - you must initialize Mongo first to use DB logging"
            self.destination = 'DB'

    def message(self, type, message, user='', extended_info=''):
        if self.destination == 'DB':    
            log_data = {
                'created':datetime.datetime.utcnow(),
                'message':message,
                'type':type,
                'user':user,
                'extended_info':extended_info
            }

# Path: whirlwind/db/mongo.py
# class Mongo(Singleton):
#     
#     db = None
#     
#     def __init__(self):
#         self.connection = None
#     
#     '''
#         register a collection of mongokit model objects
#     '''
#     def register_models(self,models):
#         self.connection.register(models)
#     
#     '''
#         Accessor for ui specific database.
#     '''   
#     @property
#     def ui(self):
#         return self.connection[options.db_name]
#     
#     '''
#         Useage:
#         from whirlwind.db.mongo import Mongo
#         Mongo.create(host='host.com', port='23423', username='mongouser', password='password')
#     '''
#     @staticmethod
#     def create(**kwargs):
#         db = Mongo()
#         db.connection = Connection(kwargs['host'],kwargs['port'])
#         Mongo.db = db
#         if 'debug' in kwargs:
#             print Mongo.db.connection


# Path: whirlwind/core/log.py
import pymongo, datetime, logging, os
from whirlwind.db.mongo import Mongo

'''
class Log():
    instance = None
    
    def __init__(self,type='',log_file=''):
        if type == 'FILE' and log_file != '':
            #make sure we have a log directory
            dirname, filename = os.path.split(log_file)
            if not os.path.exists(dirname):
                os.makedirs(dirname)
            
            self.destination = 'FILE'
            self.file_logger = logging.getLogger('whirlwind')
            hdlr = logging.FileHandler(log_file)
            hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(user)s %(message)s %(extended_info)s'))
            self.file_logger.addHandler(hdlr)
            self.file_logger.setLevel(logging.DEBUG)
        else:
            assert Mongo.db != None, "Logger Exception - you must initialize Mongo first to use DB logging"
            self.destination = 'DB'

    def message(self, type, message, user='', extended_info=''):
        if self.destination == 'DB':    
            log_data = {
                'created':datetime.datetime.utcnow(),
                'message':message,
                'type':type,
                'user':user,
                'extended_info':extended_info
            }

            Mongo.db.ui.log.insert(log_data)