Skip to content

Commit 68d41cf

Browse files
authored
Add log module root and output levels (#534)
1 parent 5defeca commit 68d41cf

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

backend/common/log.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def setup_logging():
4141
"""
4242
# Set the logging handler and level
4343
logging.root.handlers = [InterceptHandler()]
44-
logging.root.setLevel('NOTSET')
44+
logging.root.setLevel(settings.LOG_STD_LEVEL)
4545

4646
# Remove all log handlers and propagate to root logger
4747
for name in logging.root.manager.loggerDict.keys():
@@ -69,6 +69,7 @@ def correlation_id_filter(record):
6969
handlers=[
7070
{
7171
'sink': sys.stdout,
72+
'level': settings.LOG_STD_LEVEL,
7273
'filter': lambda record: correlation_id_filter(record),
7374
'format': settings.LOG_STD_FORMAT,
7475
}
@@ -98,7 +99,7 @@ def set_custom_logfile():
9899
# stdout file
99100
logger.add(
100101
str(log_access_file),
101-
level=settings.LOG_ACCESS_LEVEL,
102+
level=settings.LOG_ACCESS_FILE_LEVEL,
102103
filter=lambda record: record['level'].no <= 25,
103104
backtrace=False,
104105
diagnose=False,
@@ -108,7 +109,7 @@ def set_custom_logfile():
108109
# stderr file
109110
logger.add(
110111
str(log_error_file),
111-
level=settings.LOG_ERROR_LEVEL,
112+
level=settings.LOG_ERROR_FILE_LEVEL,
112113
filter=lambda record: record['level'].no >= 30,
113114
backtrace=True,
114115
diagnose=True,

backend/core/conf.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ class Settings(BaseSettings):
9595
COOKIE_REFRESH_TOKEN_EXPIRE_SECONDS: int = TOKEN_REFRESH_EXPIRE_SECONDS
9696

9797
# Log
98+
LOG_CID_DEFAULT_VALUE: str = '-'
99+
LOG_CID_UUID_LENGTH: int = 32 # must <= 32
100+
LOG_STD_LEVEL: str = 'INFO'
101+
LOG_ACCESS_FILE_LEVEL: str = 'INFO'
102+
LOG_ERROR_FILE_LEVEL: str = 'ERROR'
98103
LOG_STD_FORMAT: str = (
99104
'<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</> | <lvl>{level: <8}</> | '
100105
'<cyan> {correlation_id} </> | <lvl>{message}</>'
@@ -103,10 +108,6 @@ class Settings(BaseSettings):
103108
'<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</> | <lvl>{level: <8}</> | '
104109
'<cyan> {correlation_id} </> | <lvl>{message}</>'
105110
)
106-
LOG_CID_DEFAULT_VALUE: str = '-'
107-
LOG_CID_UUID_LENGTH: int = 32 # must <= 32
108-
LOG_ACCESS_LEVEL: str = 'INFO'
109-
LOG_ERROR_LEVEL: str = 'ERROR'
110111
LOG_ACCESS_FILENAME: str = 'fba_access.log'
111112
LOG_ERROR_FILENAME: str = 'fba_error.log'
112113

0 commit comments

Comments
 (0)