-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_funcs.py
34 lines (26 loc) · 1010 Bytes
/
helper_funcs.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
import datetime
import logging
import os
def create_experiment_folder(folder_name='Experiments'):
directory = os.getcwd() + '/' + folder_name + '/'
folder_name = str(datetime.datetime.now())
path_of_folder = directory + folder_name
os.makedirs(path_of_folder)
return path_of_folder, path_of_folder[:path_of_folder.rfind('/')]
def create_logger(*, name, p):
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
# create file handler which logs even debug messages
fh = logging.FileHandler(p + '/info.log')
fh.setLevel(logging.INFO)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
fh.setFormatter(formatter)
# add the handlers to logger
logger.addHandler(ch)
logger.addHandler(fh)
return logger