-
Notifications
You must be signed in to change notification settings - Fork 14
Addition of TimedRotatingFileHandler to log_config.yaml for iCtrl's logging configuration #46
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
base: main
Are you sure you want to change the base?
Changes from all commits
1905de1
0c148d0
5cac6ff
7ccff0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,22 +21,26 @@ | |
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 | ||
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__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we keep Line 29 and remove this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reasoning for this was explained in PR#48, but I forgot I also made the changes here since these changes were not merged. I can collapse the other PR onto this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Consider initializing the logger only once. The logger is initialized in both the exception and else blocks. Consider initializing it once before the try block and reusing it to reduce duplication. +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
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) Also applies to: 43-43 |
||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the import statement to match usage.
The code imports
application.paths
but later usespaths
directly, which will cause an undefined name error.📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.8.2)
24-24:
application.paths
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)