-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmylog.py
34 lines (28 loc) · 1.03 KB
/
mylog.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 logging
from datetime import datetime
def setup_logger(logger_name, log_file, level=logging.INFO):
l = logging.getLogger(logger_name)
if l.hasHandlers():
l.handlers.clear()
formatter = logging.Formatter('%(levelname)s : %(message)s')
fileHandler = logging.FileHandler(log_file, mode='w')
fileHandler.setFormatter(formatter)
l.setLevel(level)
l.addHandler(fileHandler)
l.propagate = False
def setup_csv_logger(logger_name, log_file, level=logging.INFO):
l = logging.getLogger(logger_name)
if l.hasHandlers():
l.handlers.clear()
formatter = logging.Formatter('%(message)s')
fileHandler = logging.FileHandler(log_file, mode='w')
fileHandler.setFormatter(formatter)
l.setLevel(level)
l.addHandler(fileHandler)
l.propagate = False
l.info('Action number,Action,Item found,Estimated time,Bonus,Malus,Path')
LOG = 'log.log'
setup_logger('main', LOG)
logger = logging.getLogger('main')
logger.info(datetime.now().strftime("%H:%M:%S"))
logger.propagate = False