0

my settings.py for LOGGER is as below,

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
    'json': {
        '()': 'sample_app.json_log_formatter.JSONFormatter',
    },
  },
'handlers': {
    'console': {
        'class': 'logging.StreamHandler',
        'stream': sys.stdout,
        #'level': '',
        'formatter': 'json'
    },
},
'loggers': {
    '': {
        'handlers': ['console'],
        'level': 'INFO',
        #'propogate': True,
    },
},
}

Now when there is any unhandled exceptions like var = abc and abc is not defined I get my logs 2 times,

one with my handler so the traceback error is in json format and the second is again the same error without json format it is coming from django.request.

Note: I have not added any extra logger line in my code . I just want all my unhandled exceptions also in json format but only once. so that when I send to ELK its clean

Naggappan Ramukannan
  • 2,564
  • 9
  • 36
  • 59

1 Answers1

0

I got the settings changes as below,

'loggers': {
    '': {
        'handlers': ['console'],
        'level': 'DEBUG',
        'propogate': True,
    },
    'django': {
        'handlers': ['console'],
        'propagate': False,
        'level': 'INFO'
    },

So here we making ll default django request to INFO level and propagate to false so it will not appear once . And this will override the root level logging config where in above example DEBUG is default for other applications (like my django apps) and INFO level for django logs.

Naggappan Ramukannan
  • 2,564
  • 9
  • 36
  • 59