Skip to main content

A simple mongo based logger

Project description

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

https://coveralls.io/repos/gnulnx/django-mongolog/badge.svg?branch=master&service=github:target:https://coveralls.io/github/gnulnx/django-mongolog?branch=master

Quick start

  1. Add “mongolog” to your INSTALLED_APPS 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 your management shell:

    ./manage.py shell
  2. Create a couple of log entries
    import logging
    logger = logging.getLogger(__name__)
    
    logger.debug("A debug message")
    logger.info("An info message")
    logger.warning("A warning message")
    logger.error("An error message")
    try:
        raise ValueError("Bad Value")
    except ValueError as e:
        logger.exception("An exception message")
  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 mongolog handler 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.3.2.tar.gz (19.6 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-mongolog-0.3.2.tar.gz
Algorithm Hash digest
SHA256 fe62663514f1292ee8db072614a70fb35749f8b787636a486305a1a470c73c50
MD5 748b8cfcb7bf8cdf481e8e4d0bbe1a24
BLAKE2b-256 3a0ead90a30ba1ce2f627102771519c3efe44b55bef3d61141421c48b4773b62

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