-
Notifications
You must be signed in to change notification settings - Fork 5
/
log.py
36 lines (21 loc) · 1023 Bytes
/
log.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
33
34
35
36
import logging
def setup_logger(bot_name, level=logging.INFO):
# Create a logger object with the bot's name
logger = logging.getLogger(bot_name)
logger.setLevel(level)
# Create a console handler with a higher log level
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG) # This can be adjusted as needed
# Create a file handler for logging to a file
file_handler = logging.FileHandler(f'{bot_name}.log')
file_handler.setLevel(logging.INFO) # Log level for the file
# Create a formatter that includes the bot name and other relevant details
formatter = logging.Formatter(f'%(asctime)-25s | {bot_name} | %(levelname)-8s | %(message)s')
console_handler.setFormatter(formatter)
file_handler.setFormatter(formatter)
# Add the console and file handlers to the logger
logger.addHandler(console_handler)
logger.addHandler(file_handler)
return logger
# Initialize the logger
logger = setup_logger('ServerManagerBot')