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

Improve server logging #9257

Open
wants to merge 3 commits into
base: master
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
6 changes: 2 additions & 4 deletions server/parsec/asgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ async def serve_parsec_asgi_app(
server_header=False,
headers=[("Server", server_header)],
log_level="info",
# Remove default log config to inherit instead the one we set in `parsec.logging`
log_config=None,
ssl_keyfile=ssl_keyfile,
ssl_certfile=ssl_certfile,
workers=workers,
Expand All @@ -146,10 +148,6 @@ async def serve_parsec_asgi_app(
# Force a shutdown after 10 seconds, in case of a graceful shutdown failure
# See the `Server` docstring for more information
timeout_graceful_shutdown=10,
# TODO: configure access log format:
# Timestamp is added by the log processor configured in `parsec.logging`,
# here we configure peer address + req line + rep status + rep body size + time
# (e.g. "GET 88.0.12.52:54160 /foo 1.1 404 823o 12343ms")
)
server = Server(config)

Expand Down
13 changes: 8 additions & 5 deletions server/parsec/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
S3BlockStoreConfig,
SWIFTBlockStoreConfig,
)
from parsec.logging import configure_logging, enable_sentry_logging
from parsec.logging import LogFormat, configure_logging, enable_sentry_logging

P = ParamSpec("P")
R = TypeVar("R")
Expand All @@ -59,8 +59,8 @@ def _logging_config_options(fn: Callable[P, R]) -> Callable[Concatenate[str, str
@click.option(
"--log-format",
"-f",
type=click.Choice(("CONSOLE", "JSON"), case_sensitive=False),
default="CONSOLE",
type=click.Choice([x.name for x in LogFormat], case_sensitive=False),
default=LogFormat.CONSOLE.name,
show_default=True,
envvar="PARSEC_LOG_FORMAT",
show_envvar=True,
Expand Down Expand Up @@ -96,12 +96,15 @@ def open_log_file() -> Iterator[TextIO]:
yield cast(TextIO, click.open_file(filename=log_file, mode="w"))

parsed_log_level = LogLevel[log_level.upper()]
parsed_log_format = LogFormat[log_format.upper()]
kwargs["log_level"] = parsed_log_level
kwargs["log_format"] = log_format
kwargs["log_format"] = parsed_log_format
kwargs["log_file"] = log_file

with open_log_file() as fd:
configure_logging(log_level=parsed_log_level, log_format=log_format, log_stream=fd)
configure_logging(
log_level=parsed_log_level, log_format=parsed_log_format, log_stream=fd
)

return fn(*args, **kwargs)

Expand Down
Loading
Loading