Skip to content

Commit

Permalink
fixed comments and installer
Browse files Browse the repository at this point in the history
  • Loading branch information
andreisavu committed Sep 9, 2009
1 parent 6151939 commit 510fa3d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
6 changes: 0 additions & 6 deletions TODO

This file was deleted.

7 changes: 5 additions & 2 deletions mongolog/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
class MongoHandler(logging.Handler):
""" Custom log handler
Logs all messages to a mongo capped collection.
Logs all messages to a mongo collection. This handler is
designed to be used with the standard python logging mechanism.
"""

@staticmethod
def to(db, collection, host='localhost', port=None, level=logging.NOTSET):
""" Create a handler for a given """
return MongoHandler(Connection(host, port)[db][collection])

def __init__(self, collection, level=logging.NOTSET):
""" Init log handler and open a connection to mongo server """
""" Init log handler and store the collection handle """
logging.Handler.__init__(self, level)
self.collection = collection

def emit(self,record):
""" Store the record to the collection. Async insert """
self.collection.save(record._raw)

2 changes: 2 additions & 0 deletions mongolog/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
__all__ = ['MongoLogRecord', 'MongoLogger']

class MongoLogRecord(logging.LogRecord):

def __init__(self, name, level, fn, lno, msg, args,exc_info, func, extra=None):
logging.LogRecord.__init__(self, name, level, fn, lno, msg, args,exc_info, func)

Expand All @@ -28,6 +29,7 @@ def __init__(self, name, level, fn, lno, msg, args,exc_info, func, extra=None):
}

class MongoLogger(logging.getLoggerClass()):

def makeRecord(self, *args, **kwargs):
return MongoLogRecord(*args, **kwargs)

Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
description='Centralized logging made simple using mongodb',
author='Andrei Savu',
author_email='contact@andreisavu.ro',
url='http://github.com/andreisavu/mongodb-log/tree/master',
packages=['mongolog']
url='https://github.com/andreisavu/mongodb-log/tree/master',
packages=['mongolog'],
install_requires=['pymongo']
)
5 changes: 5 additions & 0 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class TestHandler(unittest.TestCase):

def setUp(self):
""" Create an empty database that could be used for logging """
self.db_name = '_mongolog_test'

self.conn = Connection('localhost')
Expand All @@ -18,10 +19,12 @@ def setUp(self):
self.collection = self.db['log']

def tearDown(self):
""" Drop used database """
self.conn.drop_database('_mongolog_test')


def testLogging(self):
""" Simple logging example """
log = logging.getLogger('example')
log.setLevel(logging.DEBUG)

Expand All @@ -31,3 +34,5 @@ def testLogging(self):

r = self.collection.find_one({'level':'debug', 'msg':'test'})
self.assertEquals(r['msg'], 'test')


0 comments on commit 510fa3d

Please sign in to comment.