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

Bug: Custom LoggingConfig only applies when running with --debug #3943

Open
2 of 4 tasks
JonathanCroenen opened this issue Jan 10, 2025 · 1 comment
Open
2 of 4 tasks
Labels
Bug 🐛 This is something that is not working as expected

Comments

@JonathanCroenen
Copy link

Description

When using a custom logging config (that mostly reuses litestar defaults with some minor changes), the log output uses the default config as if none was provided unless running with litestar run --debug. Running with --debug uses the expected format and filter as defined in the config.

URL to code causing the issue

No response

MCVE

import logging

from litestar.logging import LoggingConfig
from litestar import Litestar, get
from litestar.status_codes import HTTP_204_NO_CONTENT


class HeartbeatFilter(logging.Filter):
    def filter(self, record: logging.LogRecord) -> bool:
        return record.getMessage().find("GET /heartbeat") == -1


logging_config = LoggingConfig(
    version=1,
    logging_module="logging",
    disable_existing_loggers=False,
    filters={
        "heartbeat": {
            "()": HeartbeatFilter,
        },
    },
    handlers={
        "queue_listener": {
            "class": "litestar.logging.standard.QueueListenerHandler",
            "handlers": [
                logging.StreamHandler(),
            ],
            "formatter": "standard",
            "filters": ["heartbeat"],
        },
    },
    loggers={
        "": {"handlers": ["queue_listener"], "propagate": False},
        "litestar": {"handlers": ["queue_listener"], "propagate": False},
        "uvicorn": {"handlers": ["queue_listener"], "propagate": False},
    },
    root={
        "handlers": ["queue_listener"],
        "level": "INFO",
    },
)


@get("/heartbeat", status_code=HTTP_204_NO_CONTENT, sync_to_thread=False)
def heartbeat() -> None:
    return None


app = Litestar(
    path="/",
    route_handlers=[
        heartbeat,
    ],
    logging_config=logging_config,
)

Steps to reproduce

1. Run the example with `litestar run`.
2. Observe the default litestar log outputs when for example performing `curl localhost:8000/heartbeat` (colors + filter does not work).
3. Run the example with `litestar run -d` or `litestar run -r`.
4. Observe the expected changes in logging format and the filtering of logs relating to `/heartbeat` when performing `curl localhost:8000/heartbeat`.

Screenshots

No response

Logs

No response

Litestar Version

$ pip list | grep litestar
-> litestar           2.14.0
$ python --version
-> Python 3.11.11

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)
@JonathanCroenen JonathanCroenen added the Bug 🐛 This is something that is not working as expected label Jan 10, 2025
@JonathanCroenen
Copy link
Author

Maybe related to #1804 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

No branches or pull requests

1 participant