forked from under0tech/autopilot_bee_sim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
executable file
·32 lines (29 loc) · 1.02 KB
/
logger.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
import logging
import definitions as vars
from datetime import datetime
def init_logger():
logger = logging.getLogger(vars.logger_name)
logger.setLevel(logging.DEBUG)
log_file_handler = logging.FileHandler(
f'logs/log_{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}.log')
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
log_file_handler.setFormatter(formatter)
logger.addHandler(log_file_handler)
return logger
bee_logger = init_logger()
def log_message(logger, message, level='debug'):
if level == 'debug':
bee_logger.debug(message)
elif level == 'info':
bee_logger.info(message)
elif level == 'warning':
bee_logger.warning(message)
elif level == 'error':
bee_logger.error(message)
elif level == 'fatal':
bee_logger.fatal(message)
else:
raise ValueError(
"Invalid logging level. Choose from 'debug', \
'info', 'warning', 'error', or 'fatal'.")