Django Log Formatting Not Being Applied
django, logging, python
Solution
Formatters apply to handlers, not to loggers. Move those `formatter:` lines to the handler dicts and things should work as expected.
Problem
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.