Skip to content

Commit 476d08d

Browse files
committed
clean
1 parent 6944e71 commit 476d08d

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

packages/service-library/src/servicelib/logging_utils.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
_logger = logging.getLogger(__name__)
2929

30+
LogLevelInt: TypeAlias = int
31+
LogMessageStr: TypeAlias = str
3032

3133
BLACK = "\033[0;30m"
3234
BLUE = "\033[0;34m"
@@ -220,13 +222,11 @@ def setup_loggers(
220222
logger_filter_mapping: Mapping of logger names to filtered message substrings
221223
tracing_settings: OpenTelemetry tracing configuration
222224
"""
223-
# Create format string
224225
fmt = _setup_format_string(
225226
tracing_settings=tracing_settings,
226227
log_format_local_dev_enabled=log_format_local_dev_enabled,
227228
)
228229

229-
# Get all loggers and apply formatting
230230
all_loggers = _get_all_loggers()
231231
for logger in all_loggers:
232232
_set_logging_handler(
@@ -259,7 +259,6 @@ async def async_loggers_lifespan(
259259
logger_filter_mapping: Mapping of logger names to filtered message substrings
260260
tracing_settings: OpenTelemetry tracing configuration
261261
"""
262-
# Create format string
263262
fmt = _setup_format_string(
264263
tracing_settings=tracing_settings,
265264
log_format_local_dev_enabled=log_format_local_dev_enabled,
@@ -303,9 +302,12 @@ async def async_loggers_lifespan(
303302
logger.removeHandler(queue_handler)
304303

305304
# Stop the queue listener
306-
_logger.debug("Shutting down async logging listener...")
307-
listener.stop()
308-
_logger.debug("Async logging context cleanup complete")
305+
with log_context(
306+
_logger,
307+
level=logging.DEBUG,
308+
msg="Shutdown async logging listener",
309+
):
310+
listener.stop()
309311

310312
except Exception as exc:
311313
sys.stderr.write(f"Error during async logging cleanup: {exc}\n")
@@ -314,7 +316,7 @@ async def async_loggers_lifespan(
314316

315317
class LogExceptionsKwargsDict(TypedDict, total=True):
316318
logger: logging.Logger
317-
level: int
319+
level: LogLevelInt
318320
msg_prefix: str
319321
exc_info: bool
320322
stack_info: bool
@@ -323,7 +325,7 @@ class LogExceptionsKwargsDict(TypedDict, total=True):
323325
@contextmanager
324326
def log_exceptions(
325327
logger: logging.Logger,
326-
level: int,
328+
level: LogLevelInt,
327329
msg_prefix: str = "",
328330
*,
329331
exc_info: bool = False,
@@ -363,7 +365,7 @@ def log_exceptions(
363365

364366

365367
def _log_before_call(
366-
logger_obj: logging.Logger, level: int, func: Callable, *args, **kwargs
368+
logger_obj: logging.Logger, level: LogLevelInt, func: Callable, *args, **kwargs
367369
) -> dict[str, str]:
368370
# NOTE: We should avoid logging arguments but in the meantime, we are trying to
369371
# avoid exposing sensitive data in the logs. For `args` is more difficult. We could eventually
@@ -401,7 +403,7 @@ def _log_before_call(
401403

402404
def _log_after_call(
403405
logger_obj: logging.Logger,
404-
level: int,
406+
level: LogLevelInt,
405407
func: Callable,
406408
result: Any,
407409
extra_args: dict[str, str],
@@ -421,7 +423,7 @@ def _log_after_call(
421423

422424
def log_decorator(
423425
logger: logging.Logger | None,
424-
level: int = logging.DEBUG,
426+
level: LogLevelInt = logging.DEBUG,
425427
*,
426428
# NOTE: default defined by legacy: ANE defined full stack tracebacks
427429
# on exceptions
@@ -488,10 +490,6 @@ def log_catch(logger: logging.Logger, *, reraise: bool = True) -> Iterator[None]
488490
raise exc from exc
489491

490492

491-
LogLevelInt: TypeAlias = int
492-
LogMessageStr: TypeAlias = str
493-
494-
495493
def _un_capitalize(s: str) -> str:
496494
return s[:1].lower() + s[1:] if s else ""
497495

@@ -554,6 +552,8 @@ def guess_message_log_level(message: str) -> LogLevelInt:
554552
return logging.INFO
555553

556554

557-
def set_parent_module_log_level(current_module: str, desired_log_level: int) -> None:
555+
def set_parent_module_log_level(
556+
current_module: str, desired_log_level: LogLevelInt
557+
) -> None:
558558
parent_module = ".".join(current_module.split(".")[:-1])
559559
logging.getLogger(parent_module).setLevel(desired_log_level)

0 commit comments

Comments
 (0)