import logging import logging.handlers import os class SerenitasFileHandler(logging.FileHandler): """simple class that encapsulates where we store our logs""" _formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) def __init__(self, log_file): super().__init__(filename=os.path.join(os.getenv("LOG_DIR"), log_file)) self.setFormatter(SerenitasFileHandler._formatter) class SerenitasRotatingFileHandler(logging.handlers.RotatingFileHandler): """simple class that encapsulates where we store our logs""" def __init__(self, log_file, maxBytes=0, backupCount=0): super().__init__( filename=os.path.join(os.getenv("LOG_DIR"), log_file), maxBytes=maxBytes, backupCount=backupCount, ) self.setFormatter(SerenitasFileHandler._formatter)