Passed
Push — dev ( 3dc5ca...6e7e16 )
by Andreas
01:09
created

f_logging   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 20
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A check_logging_opt() 0 8 3
B writelog() 0 10 6
1
"""Определяет логирование процесса."""
2
import os
3
4
from f_getconfig import getconfig
5
6
opt_logging = getconfig()['settings']['logging']
7
opt_logname = getconfig()['settings']['logname']
8
9
10
def check_logging_opt():
11
    """Проверяет параметр логирования в конфиге."""
12
    if opt_logging is True:
13
        return True
14
    elif opt_logging is False:
15
        return False
16
    else:
17
        return 'ERR'
18
19
20
def writelog(logmsg):
21
    """Пишет лог, если так указано в конфиге."""
22
    if os.path.isfile(opt_logname) is False:
23
        pass
24
    elif check_logging_opt() is True:
25
        with open(opt_logname, 'a') as log:
26
            log.write(f'{logmsg}\n')
27
    elif check_logging_opt() == 'ERR':
28
        with open(opt_logname, 'a') as log:
29
            log.write('Logging config error!')
30