Closed kba closed 3 years ago
Messing with globals is not something I'd recommend, but it's your code, I just fixed module-level getLogger like everywhere else. Up to you.
Yes, I know – but what's the right pattern for a "library" module here?
Messing with globals is not something I'd recommend, but it's your code, I just fixed module-level getLogger like everywhere else. Up to you.
Yes, I know – but what's the right pattern for a "library" module here?
getLogger
should be a cheap operation, so I would say handle it the same as processor code: either request a logger per method or initiate a self.log
instance var in the constructor where applicable.
What do you consider extreme about the PR?
getLogger
should be a cheap operation, so I would say handle it the same as processor code: either request a logger per method or initiate aself.log
instance var in the constructor where applicable.
Not applicable unfortunately, since this module only provides functions.
What do you consider extreme about the PR?
Ok, so even if it is cheap to query the logger for each little function in a library, I'd actually like to remove the OCR-D dependency from ocrolib (it was a mistake to put it in there in the first place).
The logging cookbook says logging.getLogger
will always yield the same instances for the same name. Since ocrd_utils.logging is based on this, can we assume it is enough just do LOG = loggging.getLogger('ocrolib')
once and be done (rely on the CLI for the formatter and handler stuff)?
can we assume it is enough just do LOG = loggging.getLogger('ocrolib') once and be done (rely on the CLI for the formatter and handler stuff)?
Yes, the setOverrideLoglevel
mechanism won't work but otherwise, logging.getLogger
should be equivalent.
Yes, the
setOverrideLoglevel
mechanism won't work but otherwise
Are you sure? I thought it would catch all loggers via logging.Logger.manager.loggerDict
anyway (setting their levels to NOTSET
so the root logger's level applies).
logging.getLogger
should be equivalent.
I'd much prefer it that way (without ocrd_utils) in ocrolib then. Can I update your PR accordingly?
Are you sure? I thought it would catch all loggers via logging.Logger.manager.loggerDict anyway (setting their levels to NOTSET so the root logger's level applies).
It's a matter of sequence. If the logger has been requested once before setOverrideLoglevel, it will be set to NOTSET
. If the logger is requested afterwards from logging
directly, its level isn't overridden.
I'd much prefer it that way (without ocrd_utils) in ocrolib then. Can I update your PR accordingly?
As I said: It's your code, I just wanted to wrap up the getlogger change.
Are you sure? I thought it would catch all loggers via logging.Logger.manager.loggerDict anyway (setting their levels to NOTSET so the root logger's level applies).
It's a matter of sequence. If the logger has been requested once before setOverrideLoglevel, it will be set to
NOTSET
. If the logger is requested afterwards fromlogging
directly, its level isn't overridden.
In fact, I think if you want to use logging directly, it's actually best to revert the commit completely and just change getLogger
to logging.getLogger
. That way, the logger is requested at module load time and is in the loggerDict once setOverrideLoglevel is called.
In fact, I think if you want to use logging directly, it's actually best to revert the commit completely and just change
getLogger
tologging.getLogger
. That way, the logger is requested at module load time and is in the loggerDict once setOverrideLoglevel is called.
That's what I was going to try out.
Perhaps we should also document this usage (and correct CLI usage) in ocrd_utils/README.md
or ocrd_utils
docstring?
superseded by #71, but thanks anyway!
Messing with globals is not something I'd recommend, but it's your code, I just fixed module-level getLogger like everywhere else. Up to you.