Coverage for dynasor / logging_tools.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-16 12:31 +0000

1""" This module contains functions and variables to control dynasor's logging 

2 

3* `logger` - the module logger 

4""" 

5 

6import logging 

7import sys 

8 

9 

10# This is the root logger of dynasor. 

11logger = logging.getLogger('dynasor') 

12 

13# Will process all levels of INFO or higher. This sets the default level. 

14logger.setLevel(logging.INFO) 

15 

16# If you know what you are doing you may set this to True. 

17logger.propagate = False 

18 

19# The dynasor logger will collect events from childs and the default behavior 

20# is to print it directly to stdout. 

21ch = logging.StreamHandler(sys.stdout) 

22ch.setFormatter(logging.Formatter( 

23 r'%(levelname)s %(asctime)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S')) 

24logger.addHandler(ch) 

25 

26 

27def set_logging_level(level: str) -> None: 

28 """ 

29 Alters the logging verbosity logging is handled. 

30 

31 Possible values from least to most verbose: 

32 `CRITICAL`, `ERROR`, `WARNING`, `INFO`, `DEBUG`. 

33 

34 Parameters 

35 ---------- 

36 level 

37 Verbosity level; see `Python logging library 

38 <https://docs.python.org/3/library/logging.html>`_ for details. 

39 """ 

40 logger.setLevel(level)