Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/traitlets/log.py: 64%

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

11 statements  

1"""Grab the global logger instance.""" 

2 

3# Copyright (c) IPython Development Team. 

4# Distributed under the terms of the Modified BSD License. 

5from __future__ import annotations 

6 

7import logging 

8from typing import Any, cast 

9 

10# Add a NullHandler to silence warnings about not being 

11# initialized, per best practice for libraries. 

12_fallback = logging.getLogger("traitlets") 

13_fallback.addHandler(logging.NullHandler()) 

14 

15 

16def get_logger() -> logging.Logger | logging.LoggerAdapter[Any]: 

17 """Grab the global logger instance. 

18 

19 If a global Application is instantiated, grab its logger. 

20 Otherwise, grab the 'traitlets' library logger. 

21 """ 

22 from .config import Application 

23 

24 if Application.initialized(): 

25 return cast("logging.Logger | logging.LoggerAdapter[Any]", Application.instance().log) 

26 return _fallback