forked from yanniedog/Autocrew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging_config.py
28 lines (21 loc) · 1.01 KB
/
logging_config.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
# filename: logging_config.py
import logging
def setup_logging(log_file='autocrew.log'):
logger = logging.getLogger()
# Check if handlers already exist to prevent duplicates
if not logger.handlers:
logger.setLevel(logging.DEBUG)
file_handler = logging.FileHandler(log_file, mode='a')
file_handler.setLevel(logging.DEBUG)
file_formatter = logging.Formatter('%(asctime)s - [%(levelname)s] [%(filename)s:%(funcName)s:%(lineno)d] %(message)s')
file_handler.setFormatter(file_formatter)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_formatter = logging.Formatter('%(message)s')
console_handler.setFormatter(console_formatter)
logger.addHandler(file_handler)
logger.addHandler(console_handler)
logging.getLogger('httpx').setLevel(logging.WARNING)
def flush_log_handlers():
for handler in logging.getLogger().handlers:
handler.flush()