I have added some loggers to my django application as instructed by the django website (https://docs.djangoproject.com/en/1.7/topics/logging/#examples) but for whatever reason the logs are not applying the formats. Here is my logger setup:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(asctime)s : module %(name)s : %(message)s'
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
},
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
}
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'file_request': {
'level': 'WARNING',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(file_root, 'request' , 'wilkins_request.log'),
'maxBytes': 1024*1024*1, # 1MB
'backupCount': 0,
},
'file_backend': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filters': ['require_debug_true'],
'filename': os.path.join(file_root, 'backend' , 'wilkins_backend.log'),
'maxBytes': 1024*1024*6, # 6MB
'backupCount': 0,
},
'file_security': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(file_root, 'backend' , 'wilkins_security.log'),
'maxBytes': 1024*1024*6, # 6MB
'backupCount': 0,
},
'file_migrations': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(file_root, 'backend' , 'wilkins_migrations.log'),
'maxBytes': 1024*1024*1, # 1MB
'backupCount': 0,
},
'file_debug': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filters': ['require_debug_true'],
'filename': os.path.join(file_root, 'debug' , 'wilkins.log'),
'filters': ['require_debug_true'],
'maxBytes': 1024*1024*1, # 1MB
'backupCount': 0,
},
},
'loggers': {
'django': {
'handlers': ['null'],
'propagate': True,
'level': 'INFO',
'formatter': 'simple'
},
'django.request': {
'handlers': ['file_request'],
'level': 'WARNING',
'propagate': True,
'formatter': 'simple'
},
'django.security': {
'handlers': ['file_security'],
'level': 'INFO',
'propagate': True,
'formatter': 'simple'
},
'django.db.backends': {
'handlers': ['file_backend'],
'level': 'DEBUG',
'propagate': False,
'formatter': 'simple'
},
'django.db.backends.schema': {
'handlers': ['file_migrations'],
'level': 'DEBUG',
'propagate': False,
'formatter': 'simple'
},
'wilkins': {
'handlers': ['file_debug'],
'level': 'DEBUG',
'propagate': True,
'formatter': 'simple'
},
}
}
But my output looks like this:
(from the wilkins_request.log)
Not Found: /accounts/login9
Not Found: /accounts/login9
Not Found: /accounts/login9
Not Found: /l
Not Found: /l
Not Found: /l
Not Found: /favicon.ico
(and from wilkins.log)
Made it to the Projects view.
Made it to the Projects view.
Made it to the Projects view.
Made it to the Projects view.
I am at a total loss as to why this is happening. I am using stock Django 1.7, so I have not changed any code paths or settings in django except for this logging variable.
By default, the LOGGING setting is merged with Django's default logging configuration using the following scheme. If the disable_existing_loggers key in the LOGGING dictConfig is set to True (which is the dictConfig default if the key is missing) then all loggers from the default configuration will be disabled.
How do you disable verbose error handling and logging in Django? If you don't want to configure logging at all (or you want to manually configure logging using your own approach), you can set LOGGING_CONFIG to None . This will disable the configuration process for Django's default logging.
getLogger(name) is typically executed. The getLogger() function accepts a single argument - the logger's name. It returns a reference to a logger instance with the specified name if provided, or root if not. Multiple calls to getLogger() with the same name will return a reference to the same logger object.
The Django One-Click application employs Gunicorn and Upstart. Application level logging can be found in /var/log/upstart/gunicorn. log By default, Gunicorn logs to stderr and Upstart will collect output to stderr/stdout in /var/log/upstart/$JOB_NAME.
Formatters apply to handlers, not to loggers. Move those formatter:
lines to the handler dicts and things should work as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With