-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathlogger.py
37 lines (28 loc) · 1008 Bytes
/
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
33
34
35
36
37
# logger.py
import logging
def get_logger(name):
"""
Creates a logger with the specified name.
Args:
name (str): The name of the logger.
Returns:
Logger: Configured logger instance.
"""
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
if not logger.handlers:
# Console handler
c_handler = logging.StreamHandler()
c_handler.setLevel(logging.INFO)
# File handler
f_handler = logging.FileHandler('app.log')
f_handler.setLevel(logging.DEBUG)
# Create formatters and add them to handlers
c_format = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s')
f_format = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s')
c_handler.setFormatter(c_format)
f_handler.setFormatter(f_format)
# Add handlers to the logger
logger.addHandler(c_handler)
logger.addHandler(f_handler)
return logger