-
Notifications
You must be signed in to change notification settings - Fork 14
CLPFileHandler integration for iCtrl's logging framework #49
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
625f42f
190dfe0
4f35129
392a426
f937db9
4efa440
abf9d30
2bcb814
ada79e7
5c60c87
f593d9e
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 | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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) | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+40
to
+42
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) Improve log filename format. Consider adding a prefix to the log filename for better identification, especially if this application is part of a larger system with multiple logging components. currentDateTime = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
- filename = f"{currentDateTime}.clp.zst"
+ filename = f"ictrl_{currentDateTime}.clp.zst"
log_path = os.path.join(logDir, filename) 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.8.2)40-40: (DTZ005) |
||||||||||||||||||||||||||||||||||||||||||||||
config['handlers']['CLP_file']['fpath'] = log_path | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+36
to
+43
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. 🛠️ Refactor suggestion Add timezone awareness to datetime operations. The code uses - currentDateTime = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
+ from datetime import timezone
+ currentDateTime = datetime.now(timezone.utc).strftime('%Y-%m-%d_%H-%M-%S')
filename = f"{currentDateTime}.clp.zst" Also, consider adding error handling for the case where log directory creation fails: logDir = "logs"
- os.makedirs(logDir, exist_ok=True)
+ try:
+ os.makedirs(logDir, exist_ok=True)
+ except OSError as e:
+ logger.warning(f"Failed to create logs directory: {e}")
+ # Use current directory as fallback
+ logDir = "." 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.8.2)40-40: (DTZ005) |
||||||||||||||||||||||||||||||||||||||||||||||
logging.config.dictConfig(config) | ||||||||||||||||||||||||||||||||||||||||||||||
except Exception: | ||||||||||||||||||||||||||||||||||||||||||||||
# Fallback to a basic configuration | ||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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' | ||||||||||||||||||||||
|
||||||||||||||||||||||
Comment on lines
+10
to
14
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) Handler configuration needs a more descriptive file path. The CLP_file:
class: clp_logging.handlers.CLPFileHandler
level: DEBUG
- fpath: 'example.clp.zst'
+ fpath: 'default.clp.zst' # This will be dynamically set at runtime 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
root: | ||||||||||||||||||||||
level: DEBUG | ||||||||||||||||||||||
handlers: [console] | ||||||||||||||||||||||
handlers: [CLP_file] |
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 imported but unused CLPFileHandler.
The
CLPFileHandler
is imported but never directly used in the code. Either remove the unused import or use it directly in the code.-from clp_logging.handlers import CLPFileHandler from datetime import datetime
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.8.2)
28-28:
clp_logging.handlers.CLPFileHandler
imported but unused(F401)