Skip to content

Commit b5b2b97

Browse files
committed
Fix the streamhandler bug
1 parent d47ca1d commit b5b2b97

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/daqpytools/apps/logging_demonstrator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def test_main_functions(main_logger):
4242
main_logger.debug("example debug message")
4343
main_logger.info("example info message")
4444
main_logger.warning("example warning message")
45+
46+
# Error and critical will print twice when using stream handlers
47+
# This is because StreamHandlers add in a stream each for stdout and stderr
48+
# stderr log level set to error, so at error or above both handlers will fire
4549
main_logger.error("example error message")
4650
main_logger.critical("example critical message")
4751
main_logger.info(

src/daqpytools/logging/logger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from logging import PlaceHolder
33

4+
import sys
45
import kafka
56
import sh
67
from rich.traceback import install as rich_traceback_install
@@ -159,7 +160,7 @@ def get_daq_logger(
159160
if log_level is not logging.NOTSET:
160161
for handler in logger.handlers:
161162
# Ignore stderr handler resets, needs to be fixed at the error level
162-
if type(handler).__name__ == "StderrHandler":
163+
if isinstance(handler, logging.StreamHandler) and handler.stream == sys.stderr:
163164
continue
164165
handler.setLevel(log_level)
165166

0 commit comments

Comments
 (0)