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

Addition of TimedRotatingFileHandler to log_config.yaml for iCtrl's logging configuration #46

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,27 @@
import os
import sys

import application.paths
import yaml
from flask import Flask, Blueprint, jsonify
from werkzeug.exceptions import HTTPException
from werkzeug.serving import WSGIRequestHandler

logger = logging.getLogger(__name__)

try:
with open('log_config.yaml') as config_file:
config = yaml.safe_load(config_file.read())

config['handlers']['timedRotatingFile']['filename'] = paths.LOG_FILE_PATH
paths.makedir_if_not_exists(paths.LOGS_DIR_PATH)
logging.config.dictConfig(config)
except Exception:
# Fallback to a basic configuration
logging.basicConfig(format='%(asctime)s %(levelname)s [%(name)s:%(lineno)d] %(message)s', level=logging.INFO, force=True)

logger = logging.getLogger(__name__)
logger.exception("Logging setup failed")
else:
logger = logging.getLogger(__name__)
logger.warning("Logging setup is completed with config=%s", config)

from .Profile.Profile import Profile
Expand Down
2 changes: 2 additions & 0 deletions application/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ def makedir_if_not_exists(path):
USER_PROFILE_PATH = os.path.join(PROFILE_PATH, "user_profile.json")
PRIVATE_KEY_PATH = os.path.join(PROFILE_PATH, "private_keys")
makedir_if_not_exists(PRIVATE_KEY_PATH)
LOGS_DIR_PATH = os.path.join(PROFILE_PATH, 'logs')
LOG_FILE_PATH = os.path.join(LOGS_DIR_PATH, 'ictrl_log.log')
li-ruihao marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 9 additions & 1 deletion log_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ handlers:
level: DEBUG
formatter: default
stream: ext://sys.stderr
timedRotatingFile:
class: logging.handlers.TimedRotatingFileHandler
level: DEBUG
formatter: default
when: H
interval: 3
backupCount: 112
# filename: dynamically assigned upon the initialization of the program

root:
level: DEBUG
handlers: [console]
handlers: [console, timedRotatingFile]
Loading