File: logging_tools.py

package info (click to toggle)
python-dynasor 2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,008 kB
  • sloc: python: 5,263; sh: 20; makefile: 3
file content (46 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
""" This module contains functions and variables to control dynasor's logging

* `logger` - the module logger
"""

import logging
import sys


# This is the root logger of dynasor
logger = logging.getLogger('dynasor')

# Will process all levels of INFO or higher
logger.setLevel(logging.INFO)

# If you know what you are doing you may set this to True
logger.propagate = False

# The dynasor logger will collect events from childs and the default behaviour
# is to print it directly to stdout
ch = logging.StreamHandler(sys.stdout)
ch.setFormatter(logging.Formatter(
    r'%(levelname)s %(asctime)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S'))
logger.addHandler(ch)


def set_logging_level(level):
    """
    Alters the logging verbosity logging is handled.

    level       Numeric value

    * CRITICAL         50
    * ERROR            40
    * WARNING          30
    * INFO             20
    * DEBUG            10
    * NOTSET            0

    Parameters
    ----------
    level : int
        verbosity level; see `Python logging library
        <https://docs.python.org/3/library/logging.html>`_ for details
    """
    logger.setLevel(level)