Completed
Push — master ( 91d748...e1a893 )
by Andreas
19s queued 12s
created

f_logging.writelog()   A

Complexity

Conditions 5

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 8
rs 9.3333
c 0
b 0
f 0
cc 5
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
        with open(opt_logname, 'w') as log:
24
            pass
25
    if check_logging_opt() is True:
26
        with open(opt_logname, 'a') as log:
27
            log.write(f'{logmsg}\n')
28