forked from TheoEst/abdominal_registration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.py
39 lines (28 loc) · 812 Bytes
/
log.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
37
38
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 3 17:49:42 2020
@author: T_ESTIENNE
"""
import logging
def set_logger(log_path):
logger = logging.getLogger('main')
logger.setLevel(logging.DEBUG)
# file handler
fh = logging.FileHandler(log_path, mode='w')
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter(
'%(asctime)s :: %(levelname)s :: %(message)s',
datefmt='%d/%m/%Y %I:%M:%S %p')
fh.setFormatter(formatter)
logger.addHandler(fh)
# console handler
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
formatter = logging.Formatter('%(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
return logger
def clear_logger(log):
for handler in log.handlers:
log.removeHandler(handler)
return