Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install log4mongo

How to install log4mongo

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install log4mongo
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.1b1
1.2.1Never BuiltWhy not?
1.1b1 Available View build log
1.0 Available View build log
1.0rc2 Available View build log
1.0rc1 Available View build log
Windows (64-bit)
1.1b1
1.2.1Never BuiltWhy not?
1.1b1 Available View build log
1.0 Available View build log
1.0rc2 Available View build log
1.0rc1 Available View build log
Mac OS X (10.5+)
1.1b1
1.2.1Never BuiltWhy not?
1.1b1 Available View build log
1.0 Available View build log
1.0rc2 Available View build log
1.0rc1 Available View build log
Linux (32-bit)
1.1b1
1.2.1Never BuiltWhy not?
1.1b1 Available View build log
1.0 Available View build log
1.0rc2 Available View build log
1.0rc1 Available View build log
Linux (64-bit)
1.2.1 Available View build log
1.1b1 Available View build log
1.0 Available View build log
1.0rc2 Available View build log
1.0rc1 Available View build log
 
License
BSD
Dependencies
Lastest release
version 1.2.1 on Jan 9th, 2014

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

Author

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

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.