agdsn / hades

AG DSN Authentication and Authorization Infrastructure
MIT License
8 stars 3 forks source link

`hades.bin` scripts use unconfigured log object and hence don't emit logs #107

Closed lukasjuhrich closed 2 years ago

lukasjuhrich commented 2 years ago

In hades.bin.lease_server, the call to setup_cli_logging correctly sets everything up. However, calls to e.g. logger.info reference the old, unconfigured object which was instantiated at import time. For instance, the following log call does not work even when calling hades-lease-server with -vvv: https://github.com/agdsn/hades/blob/78782831b840188b14e37c0673a6d6e9712f64ce/src/hades/bin/lease_server.py#L50-L52

…because the logger has been instantiated at import time: https://github.com/agdsn/hades/blob/78782831b840188b14e37c0673a6d6e9712f64ce/src/hades/bin/lease_server.py#L22

Indeed, setting a breakpoint there, we get the following:

(Pdb) logger
<Logger hades.bin.lease_server (NOTSET)>
(Pdb) logging.getLogger('hades.bin.lease_server')
<Logger hades.bin.lease_server (DEBUG)>
(Pdb) logging.getLogger('hades.bin.lease_server') is logger
False

I see two ways to mitigate that:

  1. Instantiate the logger after setup_cli_logging(…) and directly pass it as a parameter when necessary
  2. Replace all logger objects in already imported hades modules by global logger; logger = logging.getLogger(__name__) after the setup_cli_logging(…) call.
lukasjuhrich commented 2 years ago

As it turns out, the reason is that the logger has been instantiated with logging.Logger and not logging.getLogger, yielding a fresh object which is completely unknown to the logging.Logger.manager.loggerDict. Changing to logger = logging.getLogger(__name__) fixes everything.