-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathlog.py
More file actions
42 lines (34 loc) · 1.26 KB
/
log.py
File metadata and controls
42 lines (34 loc) · 1.26 KB
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
39
40
41
import os
import sys
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../')
import pathlib
import logging
import logging.handlers as loghandler
from datetime import datetime
import trace
loggers = {}
LOG_LEVEL = logging.DEBUG
def setup_custom_logger(name, log_level=LOG_LEVEL):
if(not hasattr(logging,name.lower())):
trace.addLoggingLevel(name, LOG_LEVEL - 5)
if loggers.get(name.lower()):
return loggers[name.lower()]
logger = logging.getLogger(name.lower())
loggers[name] = logger
file =False # True if we want things to be printed to the file or files
formatter = logging.Formatter(fmt='%(asctime)s - %(name)s - %(levelname)s - %(module)s - %(funcName)s - line %(lineno)d - %(message)s')
path = pathlib.Path(__file__).parent.absolute()
timestamp = datetime.utcnow().isoformat()
if file:
handler = loghandler.TimedRotatingFileHandler(
filename="factai.log",
when='D', interval=1, backupCount=7,
encoding="utf-8")
else:
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.setLevel(log_level)
logger.addHandler(handler)
logger.propagate = True
return logger