Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/traitlets/log.py: 92%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Grab the global logger instance."""
3# Copyright (c) IPython Development Team.
4# Distributed under the terms of the Modified BSD License.
5from __future__ import annotations
7import logging
8from typing import Any
10_logger: logging.Logger | logging.LoggerAdapter[Any] | None = None
13def get_logger() -> logging.Logger | logging.LoggerAdapter[Any]:
14 """Grab the global logger instance.
16 If a global Application is instantiated, grab its logger.
17 Otherwise, grab the root logger.
18 """
19 global _logger # noqa: PLW0603
21 if _logger is None:
22 from .config import Application
24 if Application.initialized():
25 _logger = Application.instance().log
26 else:
27 _logger = logging.getLogger("traitlets")
28 # Add a NullHandler to silence warnings about not being
29 # initialized, per best practice for libraries.
30 _logger.addHandler(logging.NullHandler())
31 return _logger