-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
43 lines (32 loc) · 1.03 KB
/
Copy pathlogger.py
File metadata and controls
43 lines (32 loc) · 1.03 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
42
43
import os
import time
import logging
class PrinterLogger:
new = lambda *args, **kwargs: 1
info = print
warning = print
error = print
class Logger:
__logger__ = PrinterLogger
@staticmethod
def new(logPath, filename=time.strftime("%Y-%m-%d")):
if Logger.__logger__ is PrinterLogger:
if not os.path.exists(logPath):
os.makedirs(logPath)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
path = os.path.join(logPath, filename + '.log')
handler = logging.FileHandler(path)
handler.setFormatter(formatter)
logger = logging.getLogger('EARL')
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
Logger.__logger__ = logger
@staticmethod
def info(msg):
Logger.__logger__.info(msg)
@staticmethod
def warning(msg):
Logger.__logger__.warning(msg)
@staticmethod
def error( msg):
Logger.__logger__.error(msg)