Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup logging with Python native logging library. #28

Merged
merged 11 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions application/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,13 +17,24 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
li-ruihao marked this conversation as resolved.
Show resolved Hide resolved
# 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)
Expand Down Expand Up @@ -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__)
Expand Down
18 changes: 18 additions & 0 deletions log_config.yaml
Original file line number Diff line number Diff line change
@@ -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]
3 changes: 2 additions & 1 deletion publish/ictrl_be.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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={},
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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