forked from jimmy19991222/ELFNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummary_logger.py
29 lines (24 loc) · 980 Bytes
/
summary_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
import logging
import os
from tensorboardX import SummaryWriter
class TensorboardSummary(object):
def __init__(self, directory):
self.directory = directory
self.writer = SummaryWriter(log_dir=os.path.join(self.directory))
def config_logger(self, epoch):
# create logger with 'spam_application'
logger = logging.getLogger(str(epoch))
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fh = logging.FileHandler(os.path.join(self.directory, 'epoch_' + str(epoch) + '.log'))
fh.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(fh)
logger.addHandler(ch)
return logger