Skip to content

[Serve] Fix enable_access_log=False not suppressing access logs on stderr#60822

Open
kouroshHakha wants to merge 5 commits intoray-project:masterfrom
kouroshHakha:kh/fix-uvicorn-logs
Open

[Serve] Fix enable_access_log=False not suppressing access logs on stderr#60822
kouroshHakha wants to merge 5 commits intoray-project:masterfrom
kouroshHakha:kh/fix-uvicorn-logs

Conversation

@kouroshHakha
Copy link
Contributor

Summary

LoggingConfig(enable_access_log=False) does not suppress access logs from stderr. The log_access_log_filter is only applied to the file handler (memory_handler), not the stream_handler. Since RAY_SERVE_LOG_TO_STDERR defaults to True, access logs bypass the filter entirely.

Reproduction

from ray import serve
from ray.serve.schema import LoggingConfig

@serve.deployment(logging_config=LoggingConfig(enable_access_log=False))
class Hello:
    def __call__(self, request):
        return "hello"

serve.start(logging_config=LoggingConfig(enable_access_log=False))
serve.run(Hello.bind())
curl http://localhost:8000/

Expected: No access log lines in stderr.

Actual:

INFO 2026-02-07 ... -- CALL __call__ OK 0.3ms
INFO 2026-02-07 ... -- GET / 200 1.2ms

These lines appear in stderr despite enable_access_log=False being set at both deployment and global level.

Root Cause

In configure_component_logger() (ray/serve/_private/logging_utils.py), the log_access_log_filter is added to memory_handler (file handler) but never to stream_handler (stderr handler):

# stream_handler — no access log filter applied (BUG)
if RAY_SERVE_LOG_TO_STDERR or stream_handler_only:
    stream_handler = logging.StreamHandler()
    stream_handler.addFilter(log_to_stderr_filter)
    stream_handler.addFilter(ServeContextFilter())
    logger.addHandler(stream_handler)

# ...

# memory_handler — filter correctly applied
if logging_config.enable_access_log is False:
    memory_handler.addFilter(log_access_log_filter)

Fix

Add the same log_access_log_filter to the stream_handler when enable_access_log is False:

if RAY_SERVE_LOG_TO_STDERR or stream_handler_only:
    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(serve_formatter)
    stream_handler.addFilter(log_to_stderr_filter)
    stream_handler.addFilter(ServeContextFilter())
    if logging_config.enable_access_log is False:
        stream_handler.addFilter(log_access_log_filter)
    logger.addHandler(stream_handler)

A regression test (test_access_log_suppressed_in_stderr) is added to verify access logs are filtered from stderr while normal user logs still appear.

Signed-off-by: Kourosh Hakhamaneshi <kourosh@anyscale.com>
@kouroshHakha kouroshHakha requested a review from a team as a code owner February 7, 2026 03:47
Signed-off-by: Kourosh Hakhamaneshi <kourosh@anyscale.com>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a bug where access logs were not being suppressed on stderr when enable_access_log=False was specified in the logging configuration. The root cause was correctly identified as the log_access_log_filter not being applied to the stream_handler. The fix adds this filter to the stream_handler, which is consistent with the existing logic for the file-based memory_handler. The change is clear, targeted, and effectively resolves the issue. The accompanying explanation in the pull request description is excellent.

@kouroshHakha kouroshHakha added the go add ONLY when ready to merge, run all tests label Feb 7, 2026
logger = logging.getLogger("ray.serve")

@serve.deployment(
logging_config={"enable_access_log": False},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we extend this test to test both behaviors, that access log should be and shouldn't be generated based on enable_access_log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kk.

Signed-off-by: Kourosh Hakhamaneshi <kourosh@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants