mongo database handler for python logging
Project description
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.
Capped collections
Capped collections are fixed-size collections that support high-throughput operations that insert, retrieve, and delete documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.
Before switching to capped collections, read this document please: http://docs.mongodb.org/manual/core/capped-collections/
This behaviour is disabled by default. You can enable this behaviour in constructor with capped=True:
import logging from log4mongo.handlers import MongoHandler handler = MongoHandler(host='localhost', capped=True)
Tests
Tested on evnironment
Xubuntu Linux Ubuntu 12.04.1 LTS 64-bit
python 2.7.3+
pymongo 2.4.1
mongod - db version v2.0.4, 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
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file log4mongo-1.2.1.tar.gz.
File metadata
- Download URL: log4mongo-1.2.1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e96936bc7ba262ea837835bb3f9753652ae2bf3020defead439edffe706ac5b
|
|
| MD5 |
e91422d68f880f5bc91abf3218bdab81
|
|
| BLAKE2b-256 |
2a650b8132b5fe66b40ba21e4298d082718d48952576c6aaaed05bd12691348a
|