I'm using Pythons logging module. I want to log the full path of a message, like
"msg packagename.modulename.functionName lineNumber", but how can I get the package name of a message?
The logging configuration is:
LOGGING = {    
'formatters': {
    'simple': {
    'format': '[%(levelname)s] %(message)s [%(module)s %(funcName)s %(lineno)d]'
    },  
},
'handlers': {
'console': {
        'level':'INFO',
        'class':'logging.StreamHandler',
        'formatter':'simple',
    }
},
'loggers': {
    'develop': {
        'handlers': ['console'],
        'level': 'DEBUG',
        'propagate': True,
    },
}
}
and I get a logger like this:
logger = logging.getLogger('develop')
                I don't know how to get a "package name" like Java does by default, but to add the filename (which gives you just as much context), use %(pathname)s in your format string:
'format': '[%(levelname)s] %(message)s [%(pathname)s %(funcName)s %(lineno)d]'
See the documentation here: https://docs.python.org/2/library/logging.html#logrecord-attributes
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