-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.py
33 lines (26 loc) · 1.14 KB
/
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
# ----------------------------------------------Import required Modules----------------------------------------------- #
import logging
import sys
import os
# -------------------------------------------------Create logs folder------------------------------------------------- #
# create folder for all logs not just from logger
if not os.path.exists("logs"):
os.mkdir("logs")
# ------------------------------------------------Log status Function------------------------------------------------- #
# logger to log to stdout
sh = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s', datefmt='%a, %d %b %Y %H:%M:%S')
sh.setFormatter(formatter)
# train and test loggers to log to file
logger_train = logging.getLogger('')
logger_train.setLevel(logging.INFO)
fh_train = logging.FileHandler('logs/train.log')
fh_train.setFormatter(formatter)
logger_train.addHandler(fh_train)
logger_train.addHandler(sh)
logger_test = logging.getLogger('')
logger_test.setLevel(logging.INFO)
fh_test = logging.FileHandler('logs/test.log')
fh_test.setFormatter(formatter)
logger_test.addHandler(fh_test)
logger_test.addHandler(sh)