Skip to content

Commit ccb3b56

Browse files
committed
Updated the loggers to *not* propagate the events.
1 parent 0d5253b commit ccb3b56

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

friendlylog/colored_logger.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from colored import fg, attr
55
from copy import copy
6+
from friendlylog.utils import do_not_propagate
67

78

89
# Where the logs should be sent.
@@ -46,6 +47,8 @@ def format(self, record):
4647

4748

4849
_logger = logging.getLogger("friendlylog.ColoredLogger" + "-" + __name__)
50+
do_not_propagate(_logger)
51+
4952
_stream_handler = logging.StreamHandler(_STREAM)
5053
_formatter = _ColoredFormatter(
5154
fmt='[%(asctime)s.%(msecs)03d in %(pathname)s - %(funcName)s:%(lineno)4d] %(message)s', # noqa: E501

friendlylog/simple_logger.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33

44
from copy import copy
5+
from friendlylog.utils import do_not_propagate
56

67

78
# Where the logs should be sent.
@@ -36,6 +37,8 @@ def format(self, record):
3637

3738

3839
_logger = logging.getLogger("friendlyLog.SimpleLogger" + "-" + __name__)
40+
do_not_propagate(_logger)
41+
3942
_stream_handler = logging.StreamHandler(_STREAM)
4043
_formatter = _SimpleFormatter(
4144
fmt='[%(asctime)s.%(msecs)03d in %(pathname)s - %(funcName)s:%(lineno)4d] %(message)s', # noqa: E501

friendlylog/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Do not pass events logged to this logger to the handlers of higher level
2+
# (ancestor) loggers.
3+
# Fixes: https://github.com/abseil/abseil-py/issues/99
4+
def do_not_propagate(logger):
5+
logger.propagate = False

0 commit comments

Comments
 (0)