summaryrefslogtreecommitdiff
path: root/tests/test_helper.py
blob: 8976b5f8cdf877569418f78ed284774690ac4102 (plain)
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
# -*- coding: utf-8 -*-

# python std lib
import logging
import logging.config

log = logging.getLogger()


# Set the root logger to be silent so all code that uses the python logger
# will not print anything unless we want it to, then it should be specified
# in each test and reseted after that test
def _set_log_lv(level=1337, loggers=None):
    """ If no level is set then level will be so high all logging is silenced
    """
    if loggers is None:
        # If no additional loggers is specified then only apply to root logger
        log.setLevel(level)
        for handler in log.handlers:
            handler.level = level
    else:
        # If we have other logging instances specified apply to root logger and them
        if log not in loggers:
            loggers.append(log)

        for log_instance in loggers:
            log_instance.setLevel(level)
            for handler in log_instance.handlers:
                handler.level = level


# Initially silence all logging
_set_log_lv()