refactor logging into it's own file

This commit is contained in:
PC-Admin 2023-08-17 23:12:07 +08:00
parent 4e0814aa1c
commit 7ec7796c06
3 changed files with 20 additions and 25 deletions

15
logging_module.py Normal file
View File

@ -0,0 +1,15 @@
# logging_module.py
import logging
def configure_logger():
file_handler = logging.FileHandler('/var/log/matrix-synapse/redlight.log')
file_handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(file_handler)
logger.propagate = False
return logger

View File

@ -1,18 +1,8 @@
import logging
import requests
from logging_module import configure_logger
# Setting up logging:
file_handler = logging.FileHandler('/var/log/matrix-synapse/redlight.log')
file_handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(file_handler)
# Prevent logger's messages from propagating to the root logger.
logger.propagate = False
logger = configure_logger()
class RedlightAlertBot:
def __init__(self, homeserver, access_token):

View File

@ -6,19 +6,9 @@ from typing import Union
from synapse.module_api import ModuleApi, NOT_SPAM
from synapse.api.errors import AuthError
from redlight_alert_bot import RedlightAlertBot
from logging_module import configure_logger
# Setting up logging:
file_handler = logging.FileHandler('/var/log/matrix-synapse/redlight.log')
file_handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(file_handler)
# Prevent logger's messages from propagating to the root logger.
logger.propagate = False
logger = configure_logger()
class RedlightClientModule:
def __init__(self, config: dict, api: ModuleApi):