Can I Have Logging.ini File Without Root Logger?
Solution 1:
If you use the source, you'll see that you must configure a root logger:
# configure the root first
llist = cp["loggers"]["keys"]
llist = llist.split(",")
llist = list(map(lambda x: x.strip(), llist))
llist.remove("root")
section = cp["logger_root"]
root = logging.root
log = root
(where cp
is the configparser
that loads the .ini
file you passed in)
The only reason I can think of is that explicit is better than implicit, so it forces you to declare exactly what you want to do with the root logger, in case you thought it would do some magic. Though I don't thinkg that's a particularly good reason. It was probably just the way someone thought to do it at the time. If you do some further reading:
The fileConfig() API is older than the dictConfig() API and does not provide functionality to cover certain aspects of logging [... N]ote that future enhancements to configuration functionality will be added to dictConfig(), so it’s worth considering transitioning to this newer API when it’s convenient to do so.
And if you consider the dictConfig
docs, it appears that you don't have to provide a root
logger.
So it appears that you are required to specify a root handler, with no really good reason besides backwards compatibility. If you want to get around that, you'll have to either specify your settings in a Python file or import a JSON file and use the dictConfig
method.
Solution 2:
Just in case it happens to someone else, check that you have commas separating all the logger entries, as you may be missing one, having both fields' names merged.
Post a Comment for "Can I Have Logging.ini File Without Root Logger?"