andreisavu / mongodb-log

MongoDB python logging handler. Python centralized logging made easy.

This URL has Read+Write access

name age message
file .gitignore Fri Aug 28 22:04:28 -0700 2009 first commit [andreisavu]
file LICENSE Sun Sep 06 03:40:10 -0700 2009 added license [andreisavu]
file README.md Wed Dec 02 06:56:19 -0800 2009 improved readme [andreisavu]
directory mongolog/ Wed Sep 09 04:18:04 -0700 2009 added source hostname in the log record [andreisavu]
directory samples/ Mon Sep 07 03:53:04 -0700 2009 changed interface: pass collection object on cr... [andreisavu]
file setup.py Wed Sep 09 03:09:21 -0700 2009 fixed comments and installer [andreisavu]
file test.py Fri Aug 28 22:52:48 -0700 2009 test placeholder and improved readme [andreisavu]
directory tests/ Wed Sep 09 03:09:21 -0700 2009 fixed comments and installer [andreisavu]
directory tools/ Wed Sep 09 04:18:04 -0700 2009 added source hostname in the log record [andreisavu]
README.md

MongoLog : Centralized Logging made simple using MongoDB

Setup

Before using this handler for logging you will need to create a capped collection on the mongodb server.

You can do this using the following commands in the mongo shell:

    > use mongolog
    > db.createCollection('log', {capped:true, max:100000})

... and you are ready. Running stats() on log collection should show something like this:

    > db.log.stats()
    {"ns" : "mongolog.log" , "count" : 0 , "size" : 0 , 
    "storageSize" : 8192 , "nindexes" : 0 , "capped" : 1 , 
    "max" : 10 , "ok" : 1}

Usage

    import logging
    from mongolog.handlers import MongoHandler

    log = logging.getLogger('demo')
    log.setLevel(logging.DEBUG)

    log.addHandler(MongoHandler.to(db='mongolog', collection='log'))

    log.debug('Some message')

Check the samples folder for more details

Why centralized logging?

  • easy troubleshouting:
    • having the answers to why? quickly and accurately
    • for troubleshouting while the system is down
    • removed risk of loss of log information
  • resource tracking
  • security

What is MongoDB?

"Mongo is a high-performance, open source, schema-free document-oriented database."

It can eficiently store arbitrary JSON objects. You can read more at http://www.mongodb.org/

Why MongoDB is great for logging?

  • MongoDB inserts can be done asynchronously
  • old log data automatically LRU's out thanks to capped collections
  • it's fast enough for the problem
  • document-oriented / JSON is a great format for log information

Read more about this subject on the mongoDB blog: http://blog.mongodb.org

Have fun!