diff --git a/application/__init__.py b/application/__init__.py index 1392cfa..2040aba 100644 --- a/application/__init__.py +++ b/application/__init__.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 iCtrl Developers +# Copyright (c) 2021-2024 iCtrl Developers # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to @@ -17,13 +17,24 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. - +import logging.config import os import sys +import yaml from flask import Flask, Blueprint from werkzeug.serving import WSGIRequestHandler +try: + with open('log_config.yaml', 'r') as config_file: + config = yaml.safe_load(config_file.read()) + logging.config.dictConfig(config) +except Exception as ex: + print("Logging setup failed with exception = ", ex) + +logger = logging.getLogger(__name__) +logger.warning(f"Logging is set up with config={config}") + from .Profile.Profile import Profile # enable persistent HTTP connections (keep-alive) @@ -54,9 +65,11 @@ profiles: Profile if os.getenv('DBADDR') is not None: from .Profile.DBProfile import DBProfile + profiles = DBProfile(app) else: from .Profile.LocalProfile import LocalProfile + profiles = LocalProfile() api = Blueprint('api', __name__) diff --git a/log_config.yaml b/log_config.yaml new file mode 100644 index 0000000..672af5a --- /dev/null +++ b/log_config.yaml @@ -0,0 +1,18 @@ +version: 1 +disable_existing_loggers: True + +formatters: + default: + format: '%(asctime)s %(levelname)s [%(name)s:%(lineno)d] %(message)s' + datefmt: '%Y-%m-%d %H:%M:%S' + +handlers: + console: + class: logging.StreamHandler + level: DEBUG + formatter: default + stream: ext://sys.stderr + +root: + level: DEBUG + handlers: [console] diff --git a/publish/ictrl_be.spec b/publish/ictrl_be.spec index e786bfa..7ed1ac2 100644 --- a/publish/ictrl_be.spec +++ b/publish/ictrl_be.spec @@ -8,7 +8,8 @@ block_cipher = None a = Analysis(['../ictrl_be.py'], pathex=['.'], binaries=[], - datas=[('../client/build', './client')], + datas=[('../client/build', './client'), + ('../log_config.yaml', '.')], hiddenimports=[], hookspath=[], hooksconfig={}, diff --git a/requirements.txt b/requirements.txt index b018ee3..0de82e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,4 +12,5 @@ Werkzeug==2.2.2 zipstream-new==1.1.8 paramiko==3.0.0 numpy==1.24.2 +pyyaml==6.0.1 git+https://github.com/junhaoliao/simple-websocket-server#egg=SimpleWebSocketServer