-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_logger.py
45 lines (39 loc) · 1.11 KB
/
utils_logger.py
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
34
35
36
37
38
39
40
41
42
43
44
45
from pathlib import Path
import logging
from logging import config
logfile = 'logfile.log'
def empty_existing_logfile(filename: str = logfile):
file = open(filename, "r+")
file.truncate(0)
file.close()
log_config = {
'version': 1,
'root': {
'handlers': ['stdout', 'file'],
'level': 'INFO'
},
'handlers': {
'stdout': {
'formatter': 'main',
'class': 'logging.StreamHandler',
'level': 'INFO'
},
'file': {
'formatter': 'main',
'class': 'logging.FileHandler',
'level': 'INFO',
'filename': logfile,
'mode': 'a+'
},
},
'formatters': {
'main': {
# 'format': '%(asctime)s : %(levelname)s : %(module)s : %(funcName)s : %(lineno)d : Message : %(message)s',
# 'datefmt': '%Y-%m-%dT%H:%M:%S%Z'
'format': '%(asctime)s : %(levelname)s : %(module)s : %(funcName)s : %(lineno)d : %(message)s',
'datefmt': '%Y%m:%H:%M:%S'
}
},
}
config.dictConfig(log_config)
logger = logging.getLogger(__name__)