-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
33 lines (24 loc) · 785 Bytes
/
utils.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
""" utils.py
This module sets up a logfile using the current time
as the file name.
"""
import logging
import time
time_s = time.strftime("%d_%b_%H_%M_%S")
fname = "logs/{}".format(time_s)
print("Logfile created: {}".format(fname))
fh = logging.FileHandler(fname)
fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.WARNING)
# create formatter and add it to the handlers
formatstr = '%(asctime)s: %(name)s: %(levelname)s: %(message)s'
formatter = logging.Formatter(formatstr, datefmt='%d/%m %H:%M:%S')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
logger = logging.getLogger('')
logger.setLevel(logging.DEBUG)
# add the handlers to the logger
logger.addHandler(fh)
logger.addHandler(ch)