Skip to main content

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.

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

char0n (Vladimír Gorej, CodeScale s.r.o.)

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

log4mongo-1.1b1.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file log4mongo-1.1b1.tar.gz.

File metadata

  • Download URL: log4mongo-1.1b1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for log4mongo-1.1b1.tar.gz
Algorithm Hash digest
SHA256 407b30bd5bddfcc4e7dd57bb0eb175d6350abf1ff67c63777fa7779770e2c616
MD5 710fedec2b74eaacf2bec5d9b6db19d7
BLAKE2b-256 db57b95d4f4ac95c8a9f099480c99dcf1223674e33c1c8eca2eb55e77c9d40fa

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page