Skip to content

Commit

Permalink
Merge pull request #61 from ricardogsilva/55-logging-of-webapp-not-wo…
Browse files Browse the repository at this point in the history
…rking

prevent django logging config from disabling existing loggers
  • Loading branch information
francbartoli authored May 4, 2024
2 parents bb18bf7 + 0c1b2a1 commit 327735d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
20 changes: 20 additions & 0 deletions arpav_ppcv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from django.conf import settings as django_settings
from django.core import management
from rich import print
from rich.padding import Padding
from rich.panel import Panel

from . import (
config,
Expand Down Expand Up @@ -116,6 +118,7 @@ def run_server(ctx: typer.Context):
f"--port={settings.bind_port}",
f"--host={settings.bind_host}",
"--factory",
"--access-log",
]
if settings.debug:
uvicorn_args.extend(
Expand All @@ -129,6 +132,23 @@ def run_server(ctx: typer.Context):
uvicorn_args.extend(["--log-level=info"])
if (log_config_file := settings.log_config_file) is not None:
uvicorn_args.append(f"--log-config={str(log_config_file)}")

serving_str = (
f"[dim]Serving at:[/dim] [link]http://{settings.bind_host}:{settings.bind_port}[/link]\n\n"
f"[dim]Public URL:[/dim] [link]{settings.public_url}[/link]\n\n"
f"[dim]API docs:[/dim] [link]{settings.public_url}/docs[/link]"
)
panel = Panel(
(
f"{serving_str}\n\n"
f"[dim]Running in [b]{'development' if settings.debug else 'production'} mode[/b]"
),
title="ARPAV-PPCV",
expand=False,
padding=(1, 2),
style="green",
)
print(Padding(panel, 1))
sys.stdout.flush()
sys.stderr.flush()
os.execvp("uvicorn", uvicorn_args)
Expand Down
26 changes: 10 additions & 16 deletions arpav_ppcv/webapp/legacy/django_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
from pathlib import Path
from typing import Any

import yaml

from ... import config


def get_custom_django_settings(
settings: config.ArpavPpcvSettings) -> dict[str, Any]:
base_dir = str(Path(__file__).parents[3] / "backend")
time_zone = "UTC"
return {
if (config_file_path := settings.log_config_file) is not None:
log_config = yaml.safe_load(Path(config_file_path).read_text())
else:
log_config = None
result = {
"SECRET_KEY": settings.django_app.secret_key,
"DEBUG": settings.debug,
"ALLOWED_HOSTS": ["*"],
Expand Down Expand Up @@ -155,21 +161,6 @@ def get_custom_django_settings(
"EMAIL_HOST_USER": settings.django_app.email.host_user,
"EMAIL_HOST_PASSWORD": settings.django_app.email.host_password,
"EMAIL_PORT": settings.django_app.email.port,
"LOGGING": {
"version": 1,
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
},
},
"loggers": {
"django": {
"handlers": ["console"],
"propagate": True,
},
},
},
"ACCEPTED_UPLOAD_MEDIA_TYPES": [
"text/plain",
"application/x-dbf",
Expand Down Expand Up @@ -210,3 +201,6 @@ def get_custom_django_settings(
"proxy": settings.django_app.thredds.proxy,
},
}
if log_config is not None:
result["LOGGING"] = log_config
return result
1 change: 0 additions & 1 deletion dev-log-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ root:
level: WARNING
handlers:
- default
propagate: false

0 comments on commit 327735d

Please sign in to comment.