Passed
Push — main ( fedced...62aa48 )
by Jochen
01:57
created

syslog2irc.util.configure_logging()   A

Complexity

Conditions 1

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.5786

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 0
dl 0
loc 15
rs 10
c 0
b 0
f 0
ccs 1
cts 6
cp 0.1666
crap 1.5786
1
"""
2
syslog2irc.util
3
~~~~~~~~~~~~~~~
4
5
Various utilities
6
7
:Copyright: 2007-2021 Jochen Kupperschmidt
8
:License: MIT, see LICENSE for details.
9
"""
10
11 1
import logging
12 1
from logging import Formatter, StreamHandler
13 1
from threading import Thread
14 1
from typing import Callable
15
16
17 1
def configure_logging() -> None:
18
    """Configure application-specific loggers.
19
20
    Setting the log level does not affect dependencies' loggers.
21
    """
22
    # Get the parent logger of all application-specific
23
    # loggers defined in the package's modules.
24
    pkg_logger = logging.getLogger(__package__)
25
26
    # Configure handler that writes to STDERR.
27
    handler = StreamHandler()
28
    handler.setFormatter(Formatter('%(asctime)s %(levelname)-8s %(message)s'))
29
    pkg_logger.addHandler(handler)
30
31
    pkg_logger.setLevel(logging.DEBUG)
32
33
34 1
def start_thread(target: Callable, name: str) -> None:
35
    """Create, configure, and start a new thread."""
36
    t = Thread(target=target, name=name, daemon=True)
37
    t.start()
38