-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_logging.py
39 lines (30 loc) · 1.05 KB
/
app_logging.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
38
39
import logging
# Set up logging to file and console
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# File handler for logging to a file
file_handler = logging.FileHandler("app_logging.log")
file_handler.setLevel(logging.DEBUG)
# Console handler for logging to the console
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
# Define a logging format
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
file_handler.setFormatter(formatter)
console_handler.setFormatter(formatter)
# Add handlers to the logger
logger.addHandler(file_handler)
logger.addHandler(console_handler)
def log_messages():
"""
Log messages
:return: None
"""
logger.info("####### App logging examples with python #######")
logger.debug("This is a debug message")
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.error("This is an error message")
logger.critical("This is a critical message")
if __name__ == "__main__":
log_messages()