Skip to content

[Bug]: StreamHandler log levels are weirdly being overridden #44

@emmuhamm

Description

@emmuhamm

Description

Main issue

In the latest nightly NFD_DEV_260204_A9, when running daqpytools-logging-demonstrator -s the stream output will come out twice, which is very much not desirable:

(dbt) [emmuhamm@np04-srv-019 daqpytools]$ daqpytools-logging-demonstrator -s
[2026/02/04 10:41:44 UTC] DEBUG      logging_demonstrator.py:162              daqpytools_logging_demonstrator                    example debug message
[2026/02/04 10:41:44 UTC] DEBUG      logging_demonstrator.py:162              daqpytools_logging_demonstrator                    example debug message
[2026/02/04 10:41:44 UTC] INFO       logging_demonstrator.py:163              daqpytools_logging_demonstrator                    example info message
[2026/02/04 10:41:44 UTC] INFO       logging_demonstrator.py:163              daqpytools_logging_demonstrator                    example info message
...

It was discovered that the issue was what happens when you manually define a log level in the new logger instance:

new_logger : logging.Logger = get_daq_logger(
        logger_name = "daqpytools_logging_demonstrator_test",
        stream_handlers = True,
        log_level="DEBUG" # remove or include this line
        
    )
    new_logger.warning("hello, world")
    print(new_logger.__dict__)
# Log level not included
(dbt) [emmuhamm@np04-srv-019 daqpytools]$ daqpytools-logging-demonstrator -s
[2026/02/04 10:35:47 UTC] WARNING    logging_demonstrator.py:148              daqpytools_logging_demonstrator_test               hello, world
{'filters': [], 'name': 'daqpytools_logging_demonstrator_test', 'level': 0, 'parent': <RootLogger root (WARNING)>, 'propagate': True, 'handlers': [<StreamHandler <stdout> (NOTSET)>, <StreamHandler <stderr> (ERROR)>], 'disabled': False, '_cache': {30: True}, 'manager': <logging.Manager object at 0x7f56af79f580>}


# Log level included
(dbt) [emmuhamm@np04-srv-019 daqpytools]$ daqpytools-logging-demonstrator -s
[2026/02/04 10:36:07 UTC] WARNING    logging_demonstrator.py:149              daqpytools_logging_demonstrator_test               hello, world
[2026/02/04 10:36:07 UTC] WARNING    logging_demonstrator.py:149              daqpytools_logging_demonstrator_test               hello, world
{'filters': [], 'name': 'daqpytools_logging_demonstrator_test', 'level': 10, 'parent': <RootLogger root (WARNING)>, 'propagate': True, 'handlers': [<StreamHandler <stdout> (DEBUG)>, <StreamHandler <stderr> (DEBUG)>], 'disabled': False, '_cache': {30: True}, 'manager': <logging.Manager object at 0x7fb18658b580>}

In particular, see in the handlers list the stream handlers are incorrectly set. This should be fixed

Things to investigate

It should be noted that this behaviour does not exist in drunc as of NFD_DEV_260204_A9. I think this is because the root logger was set correctly with the right log level, and then the rest of the logs inherited the relevant log level from it so everything is fine.

It should be tested here as well what happens if:

  • a root logger is set with an no handlers, but with a set log level. A child handler is set to inherit the log level from the parent and then introduces the stream handlers
  • the same case where a root handler exist, but the child handler makes a new stream handler and then sets its own log level
  • scenario one, except repeat the studies with grandchildren handlers

Steps to reproduce

See above

Version and environment

Visible in NFD_DEV_260101_A9

Impact

Small/Isolated

Anything else?

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions