def get_app_logger(): global logger if logger is not None: return logger logger = logging.getLogger("app") logger.setLevel(logging.INFO) max_bytes = 24 * 1024 * 1024 file_handler = logging.handlers.RotatingFileHandler now = datetime.now() ts = now.strftime("%Y%m%d") ensure_folder(f"logs/{ts}") file_handler = file_handler(f"logs/{ts}/app.log", maxBytes=max_bytes, backupCount=5) file_handler.setLevel(logging.DEBUG) logger.addHandler(file_handler) logger.addHandler(logging.StreamHandler(sys.stdout)) return logger
def test_ensure_folder(): folder_name = str(uuid.uuid4()) ensure_folder(folder_name) assert os.path.isdir(folder_name) shutil.rmtree(folder_name)
def test_ensure_folder_deep(): folder_id = str(uuid.uuid4()) folder_name = os.path.join(folder_id, "hello") ensure_folder(folder_name) assert os.path.isdir(folder_name) shutil.rmtree(folder_id, ignore_errors=True)
def __init__(self, module_name='source'): self.environment = Environment( loader=PackageLoader(module_name, 'templates'), autoescape=select_autoescape(['html', 'xml'])) ensure_folder('out')