-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogger.py
More file actions
25 lines (20 loc) · 785 Bytes
/
logger.py
File metadata and controls
25 lines (20 loc) · 785 Bytes
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
import logging
class Logger:
def __init__(self, log_file):
self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
file_handler = logging.FileHandler(log_file)
file_handler.setFormatter(formatter)
self.logger.addHandler(file_handler)
def log(self, message, level="info"):
if level == "debug":
self.logger.debug(message)
elif level == "info":
self.logger.info(message)
elif level == "warning":
self.logger.warning(message)
elif level == "error":
self.logger.error(message)
elif level == "critical":
self.logger.critical(message)