-
Notifications
You must be signed in to change notification settings - Fork 31
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
CLI log-level ignored if config file is present #626
Comments
I'm totally aware of stuff like this is hard to catch, but I really like to see a test-fixture setup for this situation that can be integrated into |
How can I reproduce this?
does log the debug message.
does NOT log, as is expected.
|
Not sure about |
I've tried with
logs nothing as expected
I tried it with |
It's sufficient to have any loggers in your config besides the root logger. For example, [logger_ocrd]
level=INFO
handlers=consoleHandler
qualname=ocrd already prevents |
@bertsky Yep, this works since |
@M3ssman sufficient to see the bug of not honouring the CLI override! |
Actually, the logging module by itself behaves as expected even if the config file is present: def test_config_file_present_set_loglevel(logging_conf, capsys):
"""Ensure logLevel can be changed if config file present"""
# arrange
os.chdir(logging_conf)
initLogging()
test_logger = getLogger('')
# act and assert
assert test_logger.level == 20
test_logger.debug("debug output")
log_debug_output = capsys.readouterr().out
assert not log_debug_output
test_logger.info("some info")
log_info_output = capsys.readouterr().out
assert log_info_output
setOverrideLogLevel('ERROR', silent=True)
test_logger.info("info outout")
log_info_output = capsys.readouterr().out
assert not log_info_output
test_logger.error("some errs")
log_error_output = capsys.readouterr().out
assert log_error_output
assert test_logger.level != 20
assert test_logger.level == 40 What is the transformation from |
Maybe I'm just really slow today but I still cannot reproduce this [loggers]
keys=root
[handler_consoleHandler]
class=StreamHandler
formatter=defaultFormatter
args=(sys.stdout,)
[handlers]
keys=consoleHandler
[formatters]
keys=defaultFormatter
[formatter_defaultFormatter]
format=%(asctime)s.%(msecs)03d %(levelname)s %(name)s - %(message)s
datefmt=%H:%M:%S
[logger_root]
level=INFO
handlers=consoleHandler
[logger_ocrd]
level=ERROR
handlers=consoleHandler
qualname=ocrd ocrd -l DEBUG log -n ocrd.test debug naye
12:09:37.873 DEBUG ocrd.test - naye
ocrd-dummy -l DEBUG -I FOO -O BAR
12:10:15.102 DEBUG ocrd.resolver.workspace_from_url - Deriving dst_dir /home/kba/build/github.com/OCR-D/monorepo/ocrd_all/core from /home/kba/build/github.com/OCR-D/monorepo
/ocrd_all/core/mets.xml 😕 |
The logging spec was initially based on log4j conventions IIRC, hence the additional |
Your test is not realistic though. On the CLI, the decorator for
Your are missing |
@bertsky Sounds like |
Yes, there's a |
It seems we were not thorough enough in #599: Currently
--log-level
has no effect when some~/ocrd_logging.conf
is present.IIUC this is because
ocrd_utils.logging.initLogging
comes aftersetOverrideLoglevel
(so all its loggersetLevel
s get wiped out and onlyglobal _overrideLogLevel
survives), butlogging.config.fileConfig
of course does not honourocrd_utils.logging.getLogger
's_overrideLogLevel
.The text was updated successfully, but these errors were encountered: