#automatic logging vs request.logger...

1 messages · Page 1 of 1 (latest)

sleek ginkgo
#

I am trying to capture logs to a file but I noticed that only logs produced by request.logger.info but my console is also printing some additional logs such as each request reponse. It it possible to also capture that and attach it to a file handler?

@get("/heartbeat", status_code=HTTP_204_NO_CONTENT, sync_to_thread=False)
def heartbeat(request: Request) -> None:
    request.logger.info("Heartbeat")
    return None

(I want both logs from the screenshot in my file handler but currently only getting bottom one)

young crownBOT
#
Notes for automatic logging vs request.logger...
At your assistance

@sleek ginkgo

No Response?

If no response in a reasonable time, ping @Member.

Closing

To close, type !solve or byte solve.

MCVE

Please include an MCVE so that we can reproduce your issue locally.

keen basin
#

This looks like the Uvicorn or Granian access logs you are seeing? Can you provide your logging config for Litestar?

sleek ginkgo
#
logging_config = LoggingConfig(
    handlers={
        "queue_listener": {
            "class": "litestar.logging.standard.QueueListenerHandler",
            "handlers": [
                logging.StreamHandler(),
                RotatingFileHandler(
                    LOG_FILE_PATH,
                    maxBytes=10 * 1024 * 1024,
                    backupCount=5,
                ),
            ],
            "formatter": "standard",
        },
    },
    root={
        "handlers": ["queue_listener"],
        "level": "INFO",
    },

pretty standard

keen basin
#

you are missing the uvicorn and/or granian facilities

#

you'll want the uvicorn equivalents if you are using that: