dictation-toolbox / natlinkcore

Other
4 stars 4 forks source link

NatlinkCore sets logging sets dragonfly to logging to debug level #71

Closed LexiconCode closed 5 months ago

LexiconCode commented 5 months ago

The root natlink logger is set to debug. This seems to be inherited by dragonfly setting it to debug as well.

Steps to reproduce:

  1. use natlink installer or natlink or natlink virtualenv for install
  2. delete .natlink folder (why should this matter?)
  3. install natlinkcore 5.3.10 and dragonfly2 0.35.0
  4. enable dragonfly natlink config
  5. load _dragonfly_example_rule.zip
  6. see logs in natlink gui window

natlink gui window log

  "C:\Users\MainLaptop\.natlink\natlink.ini"
loading module: _dragonfly_example_rule
WARNING:monitor.init:DPI awareness could not be set; it has been set already.
INFO:engine:Initialized 'natlink' SR engine: NatlinkEngine().
DEBUG:grammar.load:Grammar sample: adding rule MainRule.
DEBUG:grammar.load:Grammar sample: loading into engine NatlinkEngine().
DEBUG:grammar.load:Grammar sample: adding rule _IntegerRef_07.
DEBUG:engine:Engine NatlinkEngine(): loading grammar sample.
DEBUG:engine.compiler:NatlinkCompiler(): Compiling grammar sample.
DEBUG:engine.compiler:NatlinkCompiler(): Compiling rule MainRule.
DEBUG:engine.compiler:NatlinkCompiler(): Compiling rule _IntegerRef_07.
DEBUG:grammar.load:Grammar sample: activating rule MainRule.
DEBUG:engine:Activating rule MainRule in grammar sample.
DEBUG:grammar.load:Grammar sample: activating rule _IntegerRef_07.

The root natlink logger is set to debug in the loader. This seems to be inherited by dragonfly setting it to debug as well. https://github.com/dictation-toolbox/natlinkcore/blob/2dd7df495cff67dc05e786666d268dfaa18763b1/src/natlinkcore/loader.py#L669-L678

Setting the default_logger.setLevel(logging.DEBUG) to info changes Dragonfly logging levels.

loading module: _dragonfly_example_rule
WARNING:monitor.init:DPI awareness could not be set; it has been set already.
INFO:engine:Initialized 'natlink' SR engine: NatlinkEngine().

Info: Natlinkcore config default logging is info but does not change Dragonfly logging. https://github.com/dictation-toolbox/natlinkcore/blob/2dd7df495cff67dc05e786666d268dfaa18763b1/src/natlinkcore/loader.py#L694-L698

https://github.com/dictation-toolbox/natlinkcore/blob/2dd7df495cff67dc05e786666d268dfaa18763b1/src/natlinkcore/loader.py#L544-L552

Dragonfly default logging levels https://github.com/dictation-toolbox/dragonfly/blob/a0682dcc64ac02deb4f5ddafdc1236d6fe007367/dragonfly/log.py#L70-L104

Dragonfly logging setup https://github.com/dictation-toolbox/dragonfly/blob/a0682dcc64ac02deb4f5ddafdc1236d6fe007367/dragonfly/log.py#L216-L232

Expected out come: Natlink logging level should not affect Dragonfly logging.

LexiconCode commented 5 months ago

Removing default_logger.setLevel(logging.DEBUG) is a fix but if the fails loader it may not be logged as DEBUG

https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library "Note It is strongly advised that you do not log to the root logger in your library. Instead, use a logger with a unique and easily identifiable name, such as the name for your library’s top-level package or module. Logging to the root logger will make it difficult or impossible for the application developer to configure the logging verbosity or handlers of your library as they wish.

Note It is strongly advised that you do not add any handlers other than NullHandler to your library’s loggers. This is because the configuration of handlers is the prerogative of the application developer who uses your library. The application developer knows their target audience and what handlers are most appropriate for their application: if you add handlers ‘under the hood’, you might well interfere with their ability to carry out unit tests and deliver logs which suit their requirements."

LexiconCode commented 5 months ago

This should be fixed now in the above PR utilizing named loggers instead of setting root longer.