-
Notifications
You must be signed in to change notification settings - Fork 32
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
ocrd_utils.initLogging: also add handler to root logger #1288
Conversation
…tent with file config and prevent imported libraries from initing logging first), but disable propagation for ocrd loggers (to avoid duplication)
But if This said, the |
Yes, the idea was to behave unintrusively as a library but as you point out, in practice we don't
Agreed.
🙏 Let's discuss on Monday, I'm all for pushing for a clean logging because that is high on the list of most painful aspects of the OCR-D software at the moment. |
What do you mean not working at all? Operandi can have its own If the application is a standalone OCR-D CLI (→
Sry, I don't understand that at all. |
Actually, I was trying to point out that we do. We do not call |
Not logging anything, and if
Yes, but there is some kind of interference because of the I am talking about the experience I had in the past. Maybe these issues are no longer there. I am not sure, because I have my hack to reconfigure the loggers at run-time after the
I was talking about the |
I will try to unwrap: Operandi on startup calls ocrd_utils.initLogging. So you are saying that
Also, have you tried calling
I don't understand how our package data log config can interfere at all, unless It sounds like what you describe has been observed when core would still do
I would hope so. Could you please try it out – perhaps even with and without this change here?
Ok, that's quite involved (I don't fully understand the InterceptHandler). Side effects being handlers and levels you don't want? (So it could also be the same issue as above?)
So you were merely saying that an optional file config should not interfere with programmatic setup? I agree – and that's what |
Because it has to be called when using core methods, and there is no workaround to avoid it (may no longer be valid).
That may be the case, yes. I will have to verify again.
Yes, absolutely. Take for instance just core (the latest version) - the The only place where everything is logged as expected to a file is the
Yes. It is not that optional in the end since core provides a default for you and the only way to avoid that is to provide a manual logging configuration file. |
…lers with propagate=false
@kba @MehmedGIT in the last 6 commits, I rewrote the entire thing. I also made sure we have no side effects between tests anymore (which haunted me for quite a while). It makes much more sense to me this way – and it works under all circumstances. Please let me know what you think. We can also defer this to v3 if deemed too radical. |
Seems some adaptations are needed inside --- Logging error ---
Traceback (most recent call last):
File "/usr/local/lib/python3.8/logging/__init__.py", line 1089, in emit
self.flush()
File "/usr/local/lib/python3.8/logging/__init__.py", line 1069, in flush
self.stream.flush()
OSError: [Errno 5] Input/output error
Call stack:
File "/home/mm/venv38-all/bin/ocrd-cis-ocropy-denoise", line 8, in <module>
sys.exit(ocrd_cis_ocropy_denoise())
File "/home/mm/venv38-all/lib/python3.8/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
File "/home/mm/venv38-all/lib/python3.8/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/home/mm/venv38-all/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/mm/venv38-all/lib/python3.8/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/home/mm/venv38-all/lib/python3.8/site-packages/ocrd_cis/ocropy/cli.py", line 28, in ocrd_cis_ocropy_denoise
return ocrd_cli_wrap_processor(OcropyDenoise, *args, **kwargs)
File "/home/mm/repos/core/build/__editable__.ocrd-2.69.0-py3-none-any/ocrd/decorators/__init__.py", line 71, in ocrd_cli_wrap_processor
check_and_run_network_agent(processorClass, subcommand, address, database, queue)
File "/home/mm/repos/core/build/__editable__.ocrd-2.69.0-py3-none-any/ocrd/decorators/__init__.py", line 196, in check_and_run_network_agent
processing_worker.start_consuming()
File "/home/mm/repos/core/build/__editable__.ocrd-2.69.0-py3-none-any/ocrd_network/processing_worker.py", line 134, in start_consuming
self.rmq_consumer.start_consuming()
File "/home/mm/repos/core/build/__editable__.ocrd-2.69.0-py3-none-any/ocrd_network/rabbitmq_utils/consumer.py", line 45, in start_consuming
self._channel.start_consuming()
File "/home/mm/venv38-all/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 1883, in start_consuming
self._process_data_events(time_limit=None)
File "/home/mm/venv38-all/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 2044, in _process_data_events
self.connection.process_data_events(time_limit=time_limit)
File "/home/mm/venv38-all/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 851, in process_data_events
self._dispatch_channel_events()
File "/home/mm/venv38-all/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 567, in _dispatch_channel_events
impl_channel._get_cookie()._dispatch_events()
File "/home/mm/venv38-all/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 1510, in _dispatch_events
consumer_info.on_message_callback(self, evt.method,
File "/home/mm/repos/core/build/__editable__.ocrd-2.69.0-py3-none-any/ocrd_network/processing_worker.py", line 110, in on_consumed_message
self.process_message(processing_message=processing_message)
File "/home/mm/repos/core/build/__editable__.ocrd-2.69.0-py3-none-any/ocrd_network/processing_worker.py", line 187, in process_message
invoke_processor(
File "/home/mm/repos/core/build/__editable__.ocrd-2.69.0-py3-none-any/ocrd_network/process_helpers.py", line 35, in invoke_processor
run_processor(
File "/home/mm/repos/core/build/__editable__.ocrd-2.69.0-py3-none-any/ocrd/processor/helpers.py", line 84, in run_processor
log.debug("Running processor %s", processorClass)
Message: 'Running processor %s'
Arguments: (<class 'ocrd_cis.ocropy.denoise.OcropyDenoise'>,) |
I may have broke |
Can you try with 192895a again? |
Works fine now. I can also see much more logging with 14:44:51.694 INFO ocrd.models.ocrd_mets.server./tmp/ocrd_network_sockets/_home_mm_repos_ocrd_network_tests_ws29_data.sock - Starting up METS server
14:44:51.704 INFO uvicorn.error - Started server process [100794]
14:44:51.704 INFO uvicorn.error - Waiting for application startup.
14:44:51.704 INFO uvicorn.error - Application startup complete.
14:44:51.704 INFO uvicorn.error - Uvicorn running on unix socket /tmp/ocrd_network_sockets/_home_mm_repos_ocrd_network_tests_ws29_data.sock (Press CTRL+C to quit) |
What do you expect to see? Our logger is not used for anything beyond |
See this recipe for how we could include more messages from Uvicorn. |
Ah, okay. I am expecting to see the |
Are you perhaps still using a METS Server installation before your extensive logging change? (That would explain why you get |
|
||
# | ||
# logger tensorflow | ||
# | ||
[logger_ocrd_tensorflow] | ||
level=ERROR | ||
handlers=consoleHandler | ||
handlers= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the semantics of setting handlers to an empty value? It's not ovious from https://docs.python.org/3/library/logging.config.html for me - I assume it's incremental, i.e. does not explicitly add a handler but does not remove existing handlers either?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends on how fileConfig
gets run. The default is disable_existing_loggers=True
, i.e. before parsing, all loggers (and their handlers) are removed, as done in our disableLogging
. See documentation.
Still, what was surprising to me is that one must add a handlers
statement, it cannot be omitted – even if one just wants the messages to get forwarded up in the hierarchy without extra handlers.
The config file is documented here BTW.
As a follow-up to ccb416b, but more general:
initLogging
should always affect the root logger''
, too. (Not just when disabling logging.)Reasons:
root
logger for our default handlersimport tensorflow
) – the place to check whether logging has been set up yet is alwaysgetLogger('').hasHandlers()
, also in Python's logging.basicConfig BTWI know we deliberately changed this to exclude the root logger earlier. But I cannot find the reasoning behind that anymore. Maybe "we are a library, not an application"? Well, I agree actually, but then just don't call
initLogging
. (Perhaps at that time we got distracted by the fact that we still did callinitLogging
unconditionally when importingocrd_utils.logging
.)BTW, IMO most places (core and modules code) can get their loggers from Python stdlib's
logging.getLogger
instead of ourocrd_utils.logging.getLogger
, because we don't add anything to that nowadays.