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

f_logging.writelog()   B

Complexity

Conditions 6

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 10
rs 8.6666
c 0
b 0
f 0
cc 6
nop 1
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