-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging_config.py
36 lines (26 loc) · 977 Bytes
/
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
29
30
31
32
33
34
35
36
# logging_config.py
import logging
import sys
def get_logger(name: str):
# Create a logger object.
logger = logging.getLogger(name)
# Set the log level.
logger.setLevel(logging.INFO)
# Create a stream handler that logs to stdout.
stream_handler = logging.StreamHandler(sys.stdout)
# Optionally set the log level for the stream handler.
stream_handler.setLevel(logging.INFO)
# Create a formatter.
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
# Set the formatter for the stream handler.
stream_handler.setFormatter(formatter)
# Add the stream handler to your logger.
logger.addHandler(stream_handler)
# Optional: output logging to specified file
# file_handler = logging.FileHandler('pokefightsimulator.log')
# file_handler.setFormatter(formatter)
# file_handler.setLevel(logging.INFO)
# logger.addHandler(file_handler)
return logger