Skip to main content

A simple mongo based logger

Project description

MongoLog is a simple mongo based log handler that can be used easly used with standard python/django logging

Quick start

Note: If you are viewing this from PyPI you may find copy and paste works better from the github README

  1. Add “mongolog” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = (
        ...
        'mongolog',
    )
  2. Add the MongoLoggerHandler to your LOGGING config:

    LOGGING = {
        'handler': {
            'mongolog': {
                'level': 'WARN',
                'class': 'mongolog.MongoLogHandler',
                'connection': 'mongodb://localhost:27017/'
            },
        },
        'loggers': {
            'django': {
                'handlers': ['console', 'mongolog'],
                'level': 'DEBUG',
                'propagate': True
            },
        },
    }
  1. Start you management shell:

    ./manage.py shell
  2. Create a a couple of log entries:

    import logging
    logger = logging.getLogger(__name__)
    
    logger.debug("A debug message")
    logger.info("An info message")
    logger.warning("A Serious warning")
    logger.error("We have an ERROR")
    try:
        raise ValueError("Bad Value")
    except ValueError as e:
        logger.exception("This is the worste exception ever")
  3. Now log into your mongo shell:

    mongo
    > use mongolog
    > db.mongolog.find({}).sort({'time.utc': -1}).limit(3)
    
    If you setup your logger with level 'WARN' like the example then
    you should now see three log entries corresponding to the warning,
    error, and exception log statements.  However, you will not see the
    debug and info statements unless you adjust the level down to 'DEBUG'.

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

django-mongolog-0.2.0.tar.gz (16.7 kB view details)

Uploaded Source

File details

Details for the file django-mongolog-0.2.0.tar.gz.

File metadata

File hashes

Hashes for django-mongolog-0.2.0.tar.gz
Algorithm Hash digest
SHA256 41512abc3a85ebd3a9a48e3d99f6b6cbd50b9e796a74dfdd34560500973a2b80
MD5 45f6667a61396f93d0abdcba348b89db
BLAKE2b-256 a9b3252f9635364d6b68a3e9ca1163895842460f13b11ca86f5a6c3f41c62af3

See more details on using hashes here.

Supported by

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