Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging levels now override CLI setting by config file #173

Closed
bertsky opened this issue Aug 28, 2018 · 7 comments
Closed

logging levels now override CLI setting by config file #173

bertsky opened this issue Aug 28, 2018 · 7 comments
Assignees

Comments

@bertsky
Copy link
Collaborator

bertsky commented Aug 28, 2018

Since #164 and v0.8 (with CONFIG_PATHS in core/ocrd/logging.py), the log level set via command line parameter (e.g. "-l DEBUG") can get overriden by settings in those config files. I think it should be the other way round.

@kba
Copy link
Member

kba commented Aug 28, 2018

Setting the log level via command line switch does this:

logging.getLogger('').setLevel(logging.getLevelName(value))

It sets the (minimum) log level for the root logger. More specific rules in the ocrd_logging.py files will override this.

What do you mean by "the other way round"? Do you want the log level specified on the command line override all loggers? That would defeat the purpose of the ocrd_logging.py override mechanism. And it's kinda difficult because loggers get created at runtime.

Couldn't you just disable the customizations in the ocrd_logging.py that override the root logger settings?

@bertsky
Copy link
Collaborator Author

bertsky commented Aug 28, 2018

If I set the log level via command line switch it will affect all loggers (e.g. DEBUG) – this is to be expected.

But the specific rules in ocrd_logging.py files will be unaffected by that CLI setting (e.g. stay at WARN) – this goes against the general principle; command line should always have precedence over config files.

@kba
Copy link
Member

kba commented Aug 29, 2018

I understand what you're saying but I still don't understand why you're using both mechanisms (command line and config file). Yes, CLI params should override config file default but not more specific rules. Minimum level for a specific logger namespace prefix, should override the generic rule.

If I set the log level via command line switch it will affect all loggers (e.g. DEBUG) – this is to be expected.

No, it will affect the root logger. The config file is parsed afterwards and its more specific rules overrride the root logger.

Don't get me wrong, it would be fun to implement this (overriding getLogger probably to enforce a global loglevel) but I'm not sure that it is a better convention. What if you want to want DEBUG statements but only WARN and above from PIL (which is quite spammy)? Or you generally want only ERROR but debug ocrd.asv.aligner.* specifically?

@bertsky
Copy link
Collaborator Author

bertsky commented Aug 29, 2018 via email

@kba
Copy link
Member

kba commented Aug 29, 2018

You are right that the current behavior of the command line flag is trivial to implement with a configuration file.

The main reason for focussing exclusively on loggers as opposed to handlers is that we assume all logging happens to the terminal (c.f. https://ocr-d.github.io/cli#logging). In a python-only setup we could use the full power of the python logging module including different handlers (and you can by using this ocrd_logging.py convention for core-based code). However, the CLI spec should be language-agnostic, e.g. also work for shell/CPP/Java implementations which might use different logging mechanisms.

You make a good point for the CLI flag being used as a last resort though. If I set the log level on the command line, it's probably to get more verbose output or no logging output at all, globally, so it makes sense to have it override the config file rules instead of vice versa.

Maybe @VolkerHartmann can offer his opinion here? If it's okay with him, I'll revise the logging as you proposed.

@bertsky
Copy link
Collaborator Author

bertsky commented Aug 29, 2018

Glad we got that discussion started ;-)

Just one more remark on implementation: I am afraid my proposal using an explicit StreamHandler for CLI's setLevel() does not in fact give the desired behaviour. Maybe there is another simple way though, perhaps utilizing loglevel NOTSET more directly…

@VolkerHartmann
Copy link

In my opinion cli parameters overwrites all other settings.
Usually you will configure special log levels for troubleshooting, which you then deactivate via --parameter WARN (or ERROR) to speed up the process again.
But it's never used to make a fine grained analysis via --parameter TRACE which will take you to logging hell.
Handlers won't be affected by this switch. There should be always a default configuration which writes all warnings and errors to stdout/stderr.

kba added a commit to kba/ocrd-core that referenced this issue Sep 17, 2018
@kba kba mentioned this issue Sep 17, 2018
@kba kba closed this as completed in cd2a0b0 Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants