This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

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

Please visit the MongoLog Users Group with any questions/suggestions. Thanks.

Quick start

  1. Add “mongolog” to your INSTALLED_APPS like this
    INSTALLED_APPS = (
        ...
        'mongolog',
    )
    
  2. Add the SimpleMongoLogHandler to your LOGGING config.
    LOGGING = {
        'version': 1,
        'handlers': {
            'mongolog': {
                'level': 'DEBUG',
                'class': 'mongolog.SimpleMongoLogHandler',
                'connection': 'mongodb://localhost:27017'
            },
        },
        'loggers': {
            '': {
                'handlers': ['mongolog'],
                'level': 'DEBUG',
                'propagate': True
            },
        },
    }
    
  1. Start your management shell:

    ./manage.py shell
    
  2. Create a couple of log entries
    import logging
    import pymongo
    logger = logging.getLogger(__name__)
    

    One of the cool things about mongolog is that it can log complex data structures in a way that makes them both human parsable and queryable. So for instance if we create the following log message:

    # Pro Tip: You can copy and paste all of this
    
    LOG_MSG = {
        'test': True,
        'test class': 'TestBaseMongoLogHandler',
        'Life': {
            'Domain': {
                'Bacteria': [
                    {
                        'name': ValueError,  # intentional bad value
                        'description': 'Just a bad description'
                    }
                ],
                'Archaea': [],
                'Eukaryota': [
                    {
                        'name': 'Excavata',
                        'description': 'Various flagellate protozoa',
                    },
                    {
                        'name': 'Amoebozoa',
                        'descritpion': 'most lobose amoeboids and slime moulds',
                    },
                    {
                        'name': 'Opisthokonta',
                        'description': 'animals, fungi, choanoflagellates, etc.',
                    },
                ]
            }
        }
    }
    

    Now let’s log our message at each of the defined log levels…

    logger.debug(LOG_MSG)
    logger.info(LOG_MSG)
    logger.warn(LOG_MSG)
    logger.error(LOG_MSG)
    try:
        raise ValueError("Bad Value")
    except ValueError as e:
        logger.exception(LOG_MSG)
        raise
    
  3. Now log into your mongo shell and look at some results
    ./mongo
    
    use mongolog
    db.mongolog.findOne({'level': "INFO"})
    

    Will produde a mongo document like:

    {
        "_id" : ObjectId("5664a22bdd162ca58f0693d2"),
        "name" : "__builtin__",
        "thread" : NumberLong("140735229362944"),
        "level" : "INFO",
        "process" : 42383,
        "module" : "<console>",
        "filename" : "<console>",
        "func" : "<module>",
        "time" : ISODate("2015-12-06T21:01:31.258Z"),
        "msg" : {
            "test" : true,
            "Life" : {
                "Domain" : {
                    "Eukaryota" : [
                        {
                            "name" : "Excavata",
                            "description" : "Various flagellate protozoa"
                        },
                        {
                            "name" : "Amoebozoa",
                            "descritpion" : "most lobose amoeboids and slime moulds"
                        },
                        {
                            "name" : "Opisthokonta",
                            "description" : "animals, fungi, choanoflagellates, etc."
                        }
                    ],
                    "Archaea" : [ ],
                    "Bacteria" : [
                        {
                            "name" : "<type 'exceptions.ValueError'>",
                            "description" : "Just a bad description"
                        }
                    ]
                }
            },
            "test class" : "TestBaseMongoLogHandler"
        },
        "path" : "<console>",
        "line" : 1
    }
    

    Take a look at the “msg” section and you will notice that all of the information from our LOG_MSG is contained under that key in standard mongo data structures. This means that we can query based on our log message. For example in your mongo shell try the following queries:

    // Find all documents logged with a 'test' key
    > db.mongolog.find({'msg.test': {$exists: true}}).count()
    5
    
    // Find all documents that have a Eukaryota name in the list of  ["Amoebozoa", "Opisthokonta"]
    > db.mongolog.find({
        'msg.Life.Domain.Eukaryota.name': {
            $in: ["Amoebozoa", "Opisthokonta"]
        }
      }).count()
    1
    
    // Same as above but only those documents logged at level INFO
    >db.mongolog.find({
        'level': 'INFO',
        'msg.Life.Domain.Eukaryota.name': {$in: ["Amoebozoa", "Opisthokonta"]},
    }).count()
    1
    
    // And again at level ERROR.
    >db.mongolog.find({
        'level': 'INFO',
        'msg.Life.Domain.Eukaryota.name': {$in: ["Amoebozoa", "Opisthokonta"]},
    }).count()
    2
    
    // Notice that now two records are returned.  This is because
    // logger.exception(...) also logs at level ERROR, but also notice that if when we
    // pretty print the records...
    >db.mongolog.find({
        'level': 'ERROR',
        'msg.Life.Domain.Eukaryota.name': {$in: ["Amoebozoa", "Opisthokonta"]},
    }).pretty()
    
    // ...that one of the entries has exception info.  When running in a real environment
    // and not the console the 'trace' section will be populated with the full stack trace.
    "exception" : {
        "info" : [
            "<type 'exceptions.ValueError'>",
            "Bad Value",
            "<traceback object at 0x106853b90>"
        ],
        "trace" :
         null
    }
    

Future Roadmap

Currently mongolog has pretty solid support for logging arbitrary datastructures. If it finds an object it doesn’t know how to natively serialize it will try to convert it to str().

The next steps are to create a set of most used query operations for probing the log.

Please give a shout out with feedback and feature requests.

Thanks

Release History

Release History

0.8.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.7.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.7.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.7.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.7.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.6.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.6.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.6.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.6.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-mongolog-0.8.1.tar.gz (32.5 kB) Copy SHA256 Checksum SHA256 Source Oct 25, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting