I have a json config file and to register the custom logger inside of it, i do the following
logging.config.dictConfig(config)
myLogger = logging.getLogger("myCustomLogger")
When I debug, I see that the first code line above calls getLogger on the logger object and registers a console handler with it. I need a handle to the same logger object and thus, I call getLogger again which I think registers the same handler again.
when I log, the same log entry gets written twice on console.
I don't see a way to get a handle of logger object from logging.config.dictConfig.
The strange thing that I observed while debugging is that when the break point goes past the second line and I check the number of handlers associated with myLogger, it is only 1 handler. This is how I check this on python console that comes with pydev eclipse plugin
myLogger.handlers[1]
It gives me an error saying index doesn't exist.
myLogger.handlers[0] works fine
Pretty brand new to python, so out of ideas at this point. Does anyone know how to get around this problem ?
EDIT:
Here is the dict config json file
{
"version": 1,
"disable_existing_loggers": true,
"formatters": {
"custom": {
"format": "%(asctime)s %(levelname)s [%(applicationName)s,%(applicationState)s] %(message)s"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "custom"
}
},
"root": {
"level": "INFO",
"handlers": ["console"]
},
"loggers": {
"myCustomLogger": {
"level": "INFO",
"handlers": ["console"],
"propagate": "false"
}
}
}
config?rootandconsoleare logging, you could add"formatter": "custom"torootand see the levels.