Skip to content

Commit 3f5580f

Browse files
committed
Remove dead code & simplify logger
1 parent c27c881 commit 3f5580f

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

firetail/logger.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,23 @@
22
import sys
33
from threading import Lock
44

5-
logger_names_with_handlers_lock = Lock()
6-
logger_names_with_handlers = set()
7-
8-
9-
def get_logger(debug):
10-
return __get_logger(debug, __name__)
5+
configured_loggers_lock = Lock()
6+
configured_loggers = set()
117

128

139
def get_stdout_logger(debug):
14-
stdout_logger = __get_logger(debug, __name__ + "_stdout", logging.StreamHandler(sys.stdout))
15-
stdout_logger.propagate = False
16-
return stdout_logger
10+
stdout_logger_name = __name__ + "_stdout"
11+
stdout_logger = logging.getLogger(stdout_logger_name)
1712

13+
requires_config = False
14+
with configured_loggers_lock:
15+
if stdout_logger_name not in configured_loggers:
16+
configured_loggers.add(stdout_logger_name)
17+
requires_config = True
1818

19-
def __get_logger(debug, name, handler=None):
20-
logger = logging.getLogger(name)
19+
if requires_config:
20+
stdout_logger.propagate = False
21+
stdout_logger.setLevel(logging.DEBUG if debug else logging.INFO)
22+
stdout_logger.addHandler(logging.StreamHandler(sys.stdout))
2123

22-
with logger_names_with_handlers_lock:
23-
if name not in logger_names_with_handlers:
24-
logger.setLevel(logging.DEBUG if debug else logging.INFO)
25-
if handler:
26-
logger.addHandler(handler)
27-
logger_names_with_handlers.add(name)
28-
29-
return logger
24+
return stdout_logger

0 commit comments

Comments
 (0)