redlight/logging_module.py

26 lines
853 B
Python
Raw Normal View History

2023-08-17 11:12:07 -04:00
# logging_module.py
import logging
2023-08-17 11:16:17 -04:00
# Setting up logging specifically for this module
2023-08-17 11:12:07 -04:00
def configure_logger():
2023-08-17 11:16:17 -04:00
# 1. Create a file handler to write logs to a specific file.
2023-08-17 11:12:07 -04:00
file_handler = logging.FileHandler('/var/log/matrix-synapse/redlight.log')
file_handler.setLevel(logging.INFO)
2023-08-17 11:16:17 -04:00
# 2. Define the format for the logs.
2023-08-17 11:12:07 -04:00
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
2023-08-17 11:16:17 -04:00
# 3. Initialize the logger for this module and set its level.
2023-08-17 11:12:07 -04:00
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
2023-08-17 11:16:17 -04:00
# 4. Attach the file handler to the logger.
2023-08-17 11:12:07 -04:00
logger.addHandler(file_handler)
2023-08-17 11:16:17 -04:00
# Prevent this logger's messages from being passed to the root logger or other handlers.
2023-08-17 11:12:07 -04:00
logger.propagate = False
2023-08-17 11:16:17 -04:00
return logger