diff --git a/application/__init__.py b/application/__init__.py index 943df74..06a449d 100644 --- a/application/__init__.py +++ b/application/__init__.py @@ -25,12 +25,22 @@ from flask import Flask, Blueprint, jsonify from werkzeug.exceptions import HTTPException from werkzeug.serving import WSGIRequestHandler +from clp_logging.handlers import CLPFileHandler +from datetime import datetime logger = logging.getLogger(__name__) try: with open('log_config.yaml') as config_file: config = yaml.safe_load(config_file.read()) + if 'handlers' in config and 'CLP_file' in config['handlers']: + logDir = "logs" + os.makedirs(logDir, exist_ok=True) + + currentDateTime = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + filename = f"{currentDateTime}.clp.zst" + log_path = os.path.join(logDir, filename) + config['handlers']['CLP_file']['fpath'] = log_path logging.config.dictConfig(config) except Exception: # Fallback to a basic configuration diff --git a/log_config.yaml b/log_config.yaml index 672af5a..c5b7fba 100644 --- a/log_config.yaml +++ b/log_config.yaml @@ -7,12 +7,11 @@ formatters: datefmt: '%Y-%m-%d %H:%M:%S' handlers: - console: - class: logging.StreamHandler + CLP_file: + class: clp_logging.handlers.CLPFileHandler level: DEBUG - formatter: default - stream: ext://sys.stderr + fpath: 'example.clp.zst' root: level: DEBUG - handlers: [console] + handlers: [CLP_file] diff --git a/requirements.txt b/requirements.txt index 0de82e6..da03937 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,5 @@ zipstream-new==1.1.8 paramiko==3.0.0 numpy==1.24.2 pyyaml==6.0.1 +clp-logging==0.0.14 git+https://github.com/junhaoliao/simple-websocket-server#egg=SimpleWebSocketServer