I am using poem-web, a rust library for building http based services but I have not been able to figure out how to enable logging so I can see why a POST endpoint is failing with Bad Request Error. It is due to deserialisation issue and not seeing the logs does not help.
Anyone knows how I can enable the logging? So when the handler function cannot deserialze the payload in a POST I can see the error in the logs?
This will be appreciated!
Poem uses tracing
for logging. You can use any tracing::Subscriber
implementation to capture the log output generated by tracing. Probably the most used library for creating a Subscriber
is tracing-subscriber
.
Here a basic example for creating a Subscriber
with tracing-subscriber
that logs all log messages created by Poem in a nice format to stdout
:
fn main() {
tracing_subscriber::fmt()
.with_env_filter("poem=trace")
.init();
// here your other code
}
If you want to show all tracing messages generated in all libraries, not just Poem, you can set .with_env_filter("trace")
, instead. See this section of how you can configure the EnvFilter
. Note that you have to import tracing-subscriber
with the env-filter
feature flag enabled for this to work.