Skip to content

Commit 5cac6ff

Browse files
committed
all changes related to logging configurations in log_config.yaml based on code review
1 parent 0c148d0 commit 5cac6ff

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

application/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,27 @@
2121
import os
2222
import sys
2323

24+
import application.paths
2425
import yaml
2526
from flask import Flask, Blueprint, jsonify
2627
from werkzeug.exceptions import HTTPException
2728
from werkzeug.serving import WSGIRequestHandler
2829

29-
logger = logging.getLogger(__name__)
30-
3130
try:
3231
with open('log_config.yaml') as config_file:
3332
config = yaml.safe_load(config_file.read())
3433

35-
os.makedirs(os.path.join(os.getcwd(), 'logs'), exist_ok=True)
34+
config['handlers']['timedRotatingFile']['filename'] = paths.LOG_FILE_PATH
35+
paths.makedir_if_not_exists(paths.LOGS_DIR_PATH)
3636
logging.config.dictConfig(config)
3737
except Exception:
3838
# Fallback to a basic configuration
3939
logging.basicConfig(format='%(asctime)s %(levelname)s [%(name)s:%(lineno)d] %(message)s', level=logging.INFO, force=True)
40+
41+
logger = logging.getLogger(__name__)
4042
logger.exception("Logging setup failed")
4143
else:
44+
logger = logging.getLogger(__name__)
4245
logger.warning("Logging setup is completed with config=%s", config)
4346

4447
from .Profile.Profile import Profile

application/paths.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ def makedir_if_not_exists(path):
3939
USER_PROFILE_PATH = os.path.join(PROFILE_PATH, "user_profile.json")
4040
PRIVATE_KEY_PATH = os.path.join(PROFILE_PATH, "private_keys")
4141
makedir_if_not_exists(PRIVATE_KEY_PATH)
42+
LOGS_DIR_PATH = os.path.join(PROFILE_PATH, 'logs')
43+
LOG_FILE_PATH = os.path.join(LOGS_DIR_PATH, 'ictrl_log.log')

log_config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version: 1
2-
disable_existing_loggers: False
2+
disable_existing_loggers: True
33

44
formatters:
55
default:
@@ -12,15 +12,15 @@ handlers:
1212
level: DEBUG
1313
formatter: default
1414
stream: ext://sys.stderr
15-
file_rotating:
15+
timedRotatingFile:
1616
class: logging.handlers.TimedRotatingFileHandler
1717
level: DEBUG
18-
filename: logs/ictrl_log.log
1918
formatter: default
20-
when: 'midnight'
21-
interval: 1
22-
backupCount: 14
19+
when: H
20+
interval: 3
21+
backupCount: 112
22+
# filename: dynamically assigned upon the initialization of the program
2323

2424
root:
2525
level: DEBUG
26-
handlers: [console, file_rotating]
26+
handlers: [console, timedRotatingFile]

0 commit comments

Comments
 (0)