Coder Social home page Coder Social logo

puentesarrin / mongodb-log Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andreisavu/mongodb-log

134.0 15.0 23.0 138 KB

MongoDB Python logging handler, Centralized logging made simple using MongoDB.

Home Page: http://www.mongodb.org/

License: BSD 2-Clause "Simplified" License

Python 89.38% HTML 10.62%

mongodb-log's Introduction

MongoLog: Centralized logging made simple using MongoDB

Travis CI status

Latest PyPI version

Number of PyPI downloads

Info

MongoDB python logging handler. Python centralized logging made easy.

Author

Andrei Savu

Maintainer

Jorge Puente Sarrín

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 MongoDB shell:

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

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

> db.log.stats()
{
        "ns" : "mongolog.log",
        "count" : 0,
        "size" : 0,
        "storageSize" : 102400,
        "numExtents" : 1,
        "nindexes" : 1,
        "lastExtentSize" : 102400,
        "paddingFactor" : 1,
        "systemFlags" : 1,
        "userFlags" : 0,
        "totalIndexSize" : 8176,
        "indexSizes" : {
                "_id_" : 8176
        },
        "capped" : true,
        "max" : 2147483647,
        "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?

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

It can eficiently store arbitrary JSON objects. You can read more at MongoDB website.

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.

Have fun!

mongodb-log's People

Contributors

andreisavu avatar clofresh avatar lilydjwg avatar luismayta avatar minimal avatar puentesarrin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongodb-log's Issues

Travis integration

The unit tests are running perfectly. So, it's better to work in usage Travis-CI.

Custom fields

Hi

Thanks for creating this package, I have a question, How can I add some custom fields in logs?

Unexpected pymongo warning

My code:

logger.addHandler(MongoHandler.to(collection="log",
    host="<url>",port=<port>,
password="<password>",username="<username>",db="<db>"))

Warning:

/env2/lib/python3.3/site-packages/pymongo/mongo_client.py:343: UserWarning: database name or authSource in URI is being ignored. If you wish to authenticate to <db>, you must provide a username and password.
  "must provide a username and password." % (db_name,))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.