forked from Chris10M/Lip2Speech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
36 lines (26 loc) · 916 Bytes
/
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
import os.path as osp
import time
import sys
import logging
import glob
import os
def setup_logger(logpth):
logfile = 'ModelLog-{}.log'.format(time.strftime('%d-%m-%Y'))
new_file = True
try:
logfile = max(glob.glob(f'{logpth}/*.log'), key=os.path.getctime)
new_file = False
except ValueError:
logfile = osp.join(logpth, logfile)
FORMAT = '%(levelname)s %(filename)s(%(lineno)d): %(message)s'
log_level = logging.INFO
logging.basicConfig(level=log_level, format=FORMAT, filename=logfile)
logging.root.addHandler(logging.StreamHandler())
if new_file:
try:
with open('model/model.py', 'r') as txt_file:
logging.getLogger().info(txt_file.read())
except FileNotFoundError: ...
return new_file
if __name__ == '__main__':
print(setup_logger('savedmodels/b1c3f549827ccdf294d1a1b219eea92b'))