Skip to content

Commit

Permalink
Streamline Gunicorn config logging
Browse files Browse the repository at this point in the history
00a3319

As in tiangolo/uvicorn-gunicorn-docker, the gunicorn_conf.py had been
configured to print a JSON dump of the custom Gunicorn configuration.
This is unnecessary, because Gunicorn already outputs its configuration
to the logger when `LOG_LEVEL=debug` is used.

This commit will remove the exception handling for `logconfig_dict`. The
`start.configure_logging` method has its own exception handling. If
additional exception handling is ever needed here, the following code
could be used:

```py
import logging

try:
    logconfig_dict = configure_logging(
        logging_conf=os.getenv("LOGGING_CONF", "inboard.logging_conf")
    )
except Exception as e:
    logger: logging.Logger = logging.getLogger()
    logger.debug(f"Error loading logging config with Gunicorn: {e}")

```
  • Loading branch information
br3ndonland committed Sep 13, 2020
1 parent 1275ac4 commit c6e04dc
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions inboard/gunicorn_conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json
import multiprocessing
import os
from pathlib import Path

from inboard.start import configure_logging

Expand Down Expand Up @@ -36,14 +34,9 @@
keepalive_str = os.getenv("KEEP_ALIVE", "5")

# Gunicorn config variables
try:
logconfig_dict = configure_logging(
logging_conf=os.getenv("LOGGING_CONF", "inboard.logging_conf")
)
except Exception as e:
if use_loglevel == "debug":
msg = "Error loading logging config with Gunicorn:"
print(f"[{Path(__file__).stem}] {msg} {e}")
logconfig_dict = configure_logging(
logging_conf=os.getenv("LOGGING_CONF", "inboard.logging_conf")
)
loglevel = use_loglevel
workers = web_concurrency
bind = use_bind
Expand All @@ -53,22 +46,3 @@
graceful_timeout = int(graceful_timeout_str)
timeout = int(timeout_str)
keepalive = int(keepalive_str)

log_data = {
# General
"host": host,
"port": port,
"use_max_workers": use_max_workers,
"workers_per_core": workers_per_core,
# Gunicorn
"loglevel": loglevel,
"workers": workers,
"bind": bind,
"graceful_timeout": graceful_timeout,
"timeout": timeout,
"keepalive": keepalive,
"errorlog": errorlog,
"accesslog": accesslog,
}
if loglevel == "debug":
print(f"[{Path(__file__).stem}] Custom configuration:", json.dumps(log_data))

0 comments on commit c6e04dc

Please # to comment.