Coder Social home page Coder Social logo

gnulnx / django-mongolog Goto Github PK

View Code? Open in Web Editor NEW
15.0 15.0 4.0 874 KB

A Simple Mongo Based Logger for Django

Home Page: http://gnulnx.github.io/django-mongolog/

License: GNU General Public License v3.0

Python 59.31% HTML 7.55% JavaScript 13.51% CSS 19.54% Shell 0.09%

django-mongolog's People

Contributors

gnulnx avatar jfurr avatar john-dowling avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

django-mongolog's Issues

wording of ValueError upon misnamed logger

I encountered the following error when I misunderstood the purpose of the logger argument to Mongolog.find(logger="badger"...), where I entered the Mongo collection name badger instead of the different logger name "mustelidae" or whatever:

ValueError at /path/to/error/url/
No BaseMongoLogHandler could be found.  Did you add on to youy logging config?

Given this:

results = Mongolog.find(
    logger='badger',
    query={
        'msg.jobid': str(jobid),
    },
    project={
        '_id': 0,
        'output': '$msg.output',
        'jobid': '$msg.jobid',
        'cmd': '$msg.cmd'
    },
)

If the badger logger isn't found in Django logging settings, perhaps a more instructive error message would be: "Please check that LOGGERS["loggers"]["badger"] is defined in your Django settings and that it points to a logging handler of class mongolog.SimpleMongoLogHandler.

ml_purge backup issue

the ml_purge command assumes localhost when calling mongodump during the backup.

This ticket is to add support for passing in host and port for command and using it in all instances of mongo related calls.

Make check_keys recursive

Currently this method only goes two layers deep. This ticket should address this by making it a recursive function that goes 'n' levels deep to replace all keys having a '.' or a '$'.

"msg" doesn't support with python format

I don't realy know why the "msg" doesn't support with python format, eg: %s, %d, etc.
I want to record all logs of django request in mongodb,
Here is the result example in mongodb;

image

But, when I test it in ./manage.py shell, it worked fine.

image

@gnulnx, can you correcting my logging please?
Here is my LOGGING.

import datetime

NOW = datetime.datetime.now()
DAY_NAME = NOW.strftime('%A').lower()

MAXIMUM_FILE_LOGS = 1024 * 1024 * 10  # 10 MB
BACKUP_COUNT = 5

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'format': '[%(levelname)s] %(asctime)s %(name)s: %(message)s'
        },
    },
    'handlers': {
        'default': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'logs/default.log',
            'maxBytes': MAXIMUM_FILE_LOGS,
            'backupCount': BACKUP_COUNT,
            'formatter': 'standard',
        },
        'mongolog': {
            'level': 'DEBUG',
            'class': 'mongolog.SimpleMongoLogHandler',

            # Set the connection string to the mongo instance.
            'connection': 'mongodb://localhost:27017',

            # define mongo collection the log handler should use.  Default is mongolog
            # This is useful if you want different handlers to use different collections
            'collection': 'mongolog',
            'formatter': 'standard',
        },
        'request_debug_handler': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'logs/request_debug.log',
            'maxBytes': MAXIMUM_FILE_LOGS,
            'backupCount': BACKUP_COUNT,
            'formatter': 'standard',
        },
        'request_error_handler': {
            'level': 'ERROR',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'logs/request_error.log',
            'maxBytes': MAXIMUM_FILE_LOGS,
            'backupCount': BACKUP_COUNT,
            'formatter': 'standard',
        },
        'mail_admins_handler': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            'email_backend': 'django.core.mail.backends.smtp.EmailBackend'
        },
    },
    'root': {
        'handlers': ['default', 'mongolog'],
        'level': 'DEBUG'
    },
    'loggers': {
        'django.request': {
            'handlers': [
                'mongolog',
                'request_debug_handler',
                'request_error_handler',
                'mail_admins_handler'
            ],
            'level': 'DEBUG',
            'propagate': False
        },
    }
}

Connecting to MongoDB Atlas

Can we use MongoDB Atlas for this Django mongolog? I've changed my connection URL to the Atlas URL but I got this error when I tried to run my app.

ValueError: Unable to configure handler 'mongolog': No replica set members match selector "Primary()"

Thank you..

Fix stack trace formatting

Currently in build 0.4.1 the stack trace is shown as a single text entry. It would be better to break this up and show it as an array.

log string formatting

FAILS: logger.info("Ensuring index %s.%s %s %s", db, col, fields, kwargs)
WORKS: logger.info("Ensuring index %s.%s %s %s" % (db, col, fields, kwargs))

Basic LogView

Start a basic LogView class that will eventually grow into a decent interface

E11000 duplicate key error collection: mongolog.mongolog

How I can handle duplicate key error, when I following this django-mongolog?

image

{
  code: 11000, 
  errmsg: 'E11000 duplicate key error collection: mongolog.mongolog index: uuid_1 dup key: { : "e5a55c46a3b759839df3d1ea99ea813f" }', 
  index: 0
}

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.