log4mongo 1.1b1
mongo database handler for python logging
log4mongo-python is mongo database handler for python logging, part of log4mongo.org project. log4mongo-python is using pymongo driver - http://github.com/mongodb/mongo-python-driver
Requirements
- python 2.7+
- pymongo
- mongo database
For more information see debian_requirements.txt and requirements.txt files.
Configuration
Example handler python configuration:
import logging
from log4mongo.handlers import MongoHandler
logger = logging.getLogger('test')
logger.addHandler(MongoHandler(host='localhost'))
logger.warning('test')
Contextual information
It is possible to decorate you document with contextual information. There are tow approaches.
1.) approach
import logging
from log4mongo.handlers import MongoHandler
handler = MongoHandler(host='localhost')
logger = logging.getLogger('test')
logger.addHandler(handler)
logging.LoggerAdapter(logger, {'ip': '127.0.0.1'}).info('test')
2.) approach
import logging
from log4mongo.handlers import MongoHandler
handler = MongoHandler(host='localhost')
logger = logging.getLogger('test')
logger.addHandler(handler)
logger.info('test', extra={'ip': '127.0.0.1'})
As you can see, second approach is more straightforward and there is no need to use LoggerAdapter.
Tests
Tested on evnironment
- Xubuntu Linux 11.10 oneiric 64-bit
- python 2.7.1+
- pymongo 2.1
- mongod - db version v1.8.2, pdfile version 4.5
- python unittest
Running tests
Before you run the test you must start mongo database. You will do so by this command:
$ mongod --dbpath /tmp/
To run the test run command:
$ python test.py $ python setup.py test
Author
References
| File | Type | Py Version | Uploaded on | Size | # downloads |
|---|---|---|---|---|---|
| log4mongo-1.1b1.tar.gz (md5) | Source | 2011-12-13 | 5KB | 398 | |
- Author: VladimÃr Gorej
- Home Page: http://log4mongo.org/display/PUB/Log4mongo+for+Python
- Download URL: http://github.com/log4mongo/log4mongo-python/tarball/master
- Keywords: mongodb mongo logging handler
- License: BSD
- Platform: any
-
Categories
- Development Status :: 4 - Beta
- Environment :: Console
- Environment :: Web Environment
- Intended Audience :: Developers
- Intended Audience :: System Administrators
- License :: OSI Approved :: BSD License
- Operating System :: OS Independent
- Programming Language :: Python
- Topic :: System :: Logging
- Topic :: System :: Monitoring
- Topic :: Utilities
- Package Index Owner: char0n.myopenid.com
- DOAP record: log4mongo-1.1b1.xml
