refactor logging into it's own file
This commit is contained in:
parent
4e0814aa1c
commit
7ec7796c06
15
logging_module.py
Normal file
15
logging_module.py
Normal 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
|
@ -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):
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user