mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-28 19:06:19 -05:00
Using sys args to set initial logging level.
This commit is contained in:
parent
b8b79280e9
commit
01b4fec009
3 changed files with 13 additions and 5 deletions
|
|
@ -42,7 +42,7 @@ from sqlalchemy.orm import Session
|
|||
|
||||
from wrolpi.dates import now, from_timestamp, seconds_to_timestamp
|
||||
from wrolpi.errors import WROLModeEnabled, NativeOnly, UnrecoverableDownloadError, LogLevelError
|
||||
from wrolpi.vars import PYTEST, DOCKERIZED, CONFIG_DIR, MEDIA_DIRECTORY, DEFAULT_HTTP_HEADERS
|
||||
from wrolpi.vars import PYTEST, DOCKERIZED, CONFIG_DIR, MEDIA_DIRECTORY, DEFAULT_HTTP_HEADERS, LOG_LEVEL
|
||||
|
||||
LOGGING_CONFIG = {
|
||||
'version': 1,
|
||||
|
|
@ -98,7 +98,7 @@ LOGGING_CONFIG = {
|
|||
},
|
||||
'root': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO'
|
||||
'level': LOG_LEVEL
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import multiprocessing
|
|||
|
||||
from sanic import Sanic
|
||||
|
||||
default_log_level = 20
|
||||
from wrolpi.vars import LOG_LEVEL_INT
|
||||
|
||||
|
||||
def attach_shared_contexts(app: Sanic):
|
||||
|
|
@ -32,7 +32,7 @@ def attach_shared_contexts(app: Sanic):
|
|||
app.shared_ctx.map_importing = manager.dict()
|
||||
# Shared lists.
|
||||
# Shared ints
|
||||
app.shared_ctx.log_level = multiprocessing.Value(ctypes.c_int, default_log_level)
|
||||
app.shared_ctx.log_level = multiprocessing.Value(ctypes.c_int, LOG_LEVEL_INT)
|
||||
|
||||
# Download Manager
|
||||
app.shared_ctx.download_manager_data = manager.dict()
|
||||
|
|
@ -86,7 +86,7 @@ def reset_shared_contexts(app: Sanic):
|
|||
))
|
||||
app.shared_ctx.map_importing.clear()
|
||||
# Shared ints
|
||||
app.shared_ctx.log_level.value = default_log_level
|
||||
app.shared_ctx.log_level.value = LOG_LEVEL_INT
|
||||
|
||||
# Download Manager
|
||||
app.shared_ctx.download_manager_data.clear()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import pathlib
|
||||
|
|
@ -44,6 +45,13 @@ def list_var(name: str, default='') -> List[str]:
|
|||
return [i for i in os.environ.get(name, default).split(',')]
|
||||
|
||||
|
||||
LOG_LEVEL_INT = logging.INFO
|
||||
if '-vv' in sys.argv:
|
||||
LOG_LEVEL_INT = logging.DEBUG
|
||||
elif '-vvv' in sys.argv:
|
||||
LOG_LEVEL_INT = logging.NOTSET
|
||||
LOG_LEVEL = logging.getLevelName(LOG_LEVEL_INT)
|
||||
|
||||
# Special environment variable set in the docker/api/Dockerfile.
|
||||
DOCKERIZED = truthy_arg(os.environ.get('DOCKER', ''))
|
||||
# tests are running
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue