Friday, July 26, 2013

Changing log filename

I have a standard logger that I would like to use for all of my applications, the only thing I want to change is the name of the file.  Is there a way to do that with out having to create a logger and handler for each of my apps.

Here is the logging settings that I am using.

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format' : "[%(asctime)s] %(levelname)s [%(module)s:%(lineno)s] %(message)s",
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
    },
    'handlers': {
        'app_logger': {
            'level':'DEBUG',
            'class':'logging.handlers.TimedRotatingFileHandler',
            'filename': '/var/log/django/app.log',
            'backupCount': 5,
            'when' : 'midnight',
            'formatter': 'standard',
        },
    },
    'loggers': {
        'myproject': {
            'handlers': ['app_logger'],
            'level': 'INFO',
        }
    }
}


In my app I would like to be able to override the 'filename': '/var/log/django/another_app.log',
import logging
log = logging.getLogger('myproject')
<change log file to '/var/log/django/another_app.log'>
log.info("Something here")

Any ideas?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment