Skip to content
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

Add --log-config cmd line parameter to stator #674

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions docker/logging_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[handlers]
keys = out, error

[handler_out]
class = StreamHandler
formatter = generic
args = (sys.stdout,)

[handler_error]
class = StreamHandler
formatter = generic
args = (sys.stderr,)

[formatters]
keys = generic

[formatter_generic]
format = [%(levelname)s] [%(name)s]: %(message)s

[loggers]
keys = root, gunicorn, django, takahe_core, takahe_stator, takahe_users, takahe_activities

[logger_root]
handlers = error
level = WARNING

[logger_gunicorn]
handlers = error
qualname = gunicorn.error
level = ERROR
propagate = 0

[logger_django]
handlers = error
qualname = django
level = ERROR
propagate = 0

[logger_takahe_core]
handlers = out
qualname = core
level = INFO

[logger_takahe_stator]
handlers = out
qualname = stator
level = INFO

[logger_takahe_users]
handlers = out
qualname = users
level = INFO

[logger_takahe_activities]
handlers = out
qualname = activities
level = INFO
11 changes: 10 additions & 1 deletion stator/management/commands/runstator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import logging.config
from typing import cast

from django.apps import apps
Expand Down Expand Up @@ -49,6 +50,12 @@ def add_arguments(self, parser):
action="append",
help="Model labels that should not be processed",
)
parser.add_argument(
"--log-config",
type=str,
default=None,
help="Configuration file for logging",
)
parser.add_argument("model_labels", nargs="*", type=str)

def handle(
Expand All @@ -59,6 +66,7 @@ def handle(
schedule_interval: int,
run_for: int,
exclude: list[str],
log_config: str,
*args,
**options
):
Expand All @@ -68,8 +76,9 @@ def handle(
format="[%(asctime)s] %(levelname)8s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=logging.INFO,
force=True,
)
if log_config:
logging.config.fileConfig(log_config)
# Resolve the models list into names
models = cast(
list[type[StatorModel]],
Expand Down