I'm trying to create a logging package for my python scripts, allowing me to log my errors on an ELK server. The problem is that I can't create an instance of my Logging class to get all my logs present in the scripts.
In my package file I set up a handler that will allow me to retrieve all the events from my scripts. The problem is that I can't use my log messages only through class Logging. I am forced to use the python logging package in each of my modules when the call is already made in my package.
PACKAGE LOGS
import logging
class Logging:
def __init__(self, module, scope, title):
self.module = module
self.scope = scope
self.title = title
def format_logs(self):
# Configuration Logging
logging.getLogger(__name__)
logging.basicConfig(filename=FILE, format='%(asctime)s :: %(levelname)s :: %(message)s', datefmt='%m/%d/%Y %I:%M:%S', level=logging.DEBUG)
# Setting up the listening file
logging.FileHandler(FILE)
EXAMPLE SCRIPTS
from packages.pkg_logs import Logging
import logging
def __init__(self, url):
self.url = url
self.init_log = Logging(self.url, SCRIPT, TITLE)
self.set_handler = self.init_log.format_logs()
logging.info("Starting script : %s on : %s" % (TITLE, url))
Waiting for your feedback for solutions.