refactor logging into it's own file 2
This commit is contained in:
parent
7ec7796c06
commit
eb69298cfe
@ -2,14 +2,25 @@
|
||||
|
||||
import logging
|
||||
|
||||
# Setting up logging specifically for this module
|
||||
def configure_logger():
|
||||
|
||||
# 1. Create a file handler to write logs to a specific file.
|
||||
file_handler = logging.FileHandler('/var/log/matrix-synapse/redlight.log')
|
||||
file_handler.setLevel(logging.INFO)
|
||||
|
||||
# 2. Define the format for the logs.
|
||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
file_handler.setFormatter(formatter)
|
||||
|
||||
# 3. Initialize the logger for this module and set its level.
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
# 4. Attach the file handler to the logger.
|
||||
logger.addHandler(file_handler)
|
||||
|
||||
# Prevent this logger's messages from being passed to the root logger or other handlers.
|
||||
logger.propagate = False
|
||||
return logger
|
||||
|
||||
return logger
|
@ -1,4 +1,4 @@
|
||||
import logging
|
||||
#import logging
|
||||
import hashlib
|
||||
import json
|
||||
import asyncio
|
||||
|
@ -1,4 +1,4 @@
|
||||
import logging
|
||||
#import logging
|
||||
import json
|
||||
import requests
|
||||
import base64
|
||||
@ -9,23 +9,9 @@ from twisted.internet import defer
|
||||
from twisted.internet.defer import inlineCallbacks
|
||||
from twisted.web.server import NOT_DONE_YET
|
||||
from twisted.web.http import OK, NO_CONTENT
|
||||
from logging_module import configure_logger
|
||||
|
||||
# Setting up logging specifically for this module:
|
||||
# 1. Create a file handler to write logs to a specific file.
|
||||
file_handler = logging.FileHandler('/var/log/matrix-synapse/redlight.log')
|
||||
file_handler.setLevel(logging.INFO)
|
||||
# 2. Define the format for the logs.
|
||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
file_handler.setFormatter(formatter)
|
||||
|
||||
# 3. Initialize the logger for this module and set its level.
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.INFO)
|
||||
# 4. Attach the file handler to the logger.
|
||||
logger.addHandler(file_handler)
|
||||
|
||||
# Prevent this logger's messages from being passed to the root logger or other handlers.
|
||||
logger.propagate = False
|
||||
logger = configure_logger()
|
||||
|
||||
class SourceDataManager:
|
||||
def __init__(self, module, config):
|
||||
|
Loading…
Reference in New Issue
Block a user