Skip to content

Commit

Permalink
Ensure loggers are singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
c-w committed Nov 26, 2018
1 parent c5fe2ee commit 53639b5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion opwen_email_server/utils/log.py
@@ -1,3 +1,4 @@
from functools import lru_cache
from logging import Formatter
from logging import Handler
from logging import Logger
Expand All @@ -18,12 +19,14 @@
from opwen_email_server.constants.logging import TELEMETRY_QUEUE_SECONDS


@lru_cache(maxsize=1)
def _get_log_handlers() -> Iterable[Handler]:
stderr = StreamHandler()
stderr.setFormatter(Formatter(STDERR))
yield stderr
return [stderr]


@lru_cache(maxsize=1)
def _get_logger() -> Logger:
log = getLogger()
for handler in _get_log_handlers():
Expand All @@ -32,6 +35,7 @@ def _get_logger() -> Logger:
return log


@lru_cache(maxsize=1)
def _get_telemetry_client() -> Optional[TelemetryClient]:
if not APPINSIGHTS_KEY:
return None
Expand Down

0 comments on commit 53639b5

Please sign in to comment.