Coverage for local_installation/dynasor/logging_tools.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-09-27 15:43 +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 

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 behaviour 

20# is to print it directly to stdout 

21ch = logging.StreamHandler(sys.stdout) 

22ch.setFormatter(logging.Formatter(r'%(levelname)s: %(message)s')) 

23logger.addHandler(ch) 

24 

25 

26def set_logging_level(level): 

27 """ 

28 Alters the logging verbosity logging is handled. 

29 

30 level Numeric value 

31 

32 * CRITICAL 50 

33 * ERROR 40 

34 * WARNING 30 

35 * INFO 20 

36 * DEBUG 10 

37 * NOTSET 0 

38 

39 Parameters 

40 ---------- 

41 level : int 

42 verbosity level; see `Python logging library 

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

44 """ 

45 logger.setLevel(level)