We have started to use Log::Any::Adapter::MojoLog in our Mojolicious application. In the startup() method we are calling
Log::Any::Adapter->set( 'MojoLog', logger => $app->log )
Now we wanted to show the request-id as additional context information. The MojoLog adapter isn't context aware: It doesn't implement the structured() method. Instead of that the Mojolicious community has invented another way to add context (mojolicious/mojo#1404). This kind of context creates another child logger for each request based on the parent application level logger $app->log. To use this child logger we have called the set() method in each Mojolicious controller action
sub ( $c ) {
Log::Any::Adapter->set( 'MojoLog', logger => $c->log )
...
}
The swapping of adapters leads to problems in nonblocking model/backend code.
[2026-03-16 13:59:29.38149] [6194] [trace] [pXXpxMu3Rci-] POST "/api/deploy"
[2026-03-16 13:59:29.38183] [6194] [trace] [pXXpxMu3Rci-] Routing to a callback
[2026-03-16 13:59:29.38271] [6194] [debug] [pXXpxMu3Rci-] Log::Any: Start timer to simulate an async operation in model 'A'
[2026-03-16 13:59:29.38315] [6194] [trace] [ZShghqqC7kuD] POST "/api/deploy"
[2026-03-16 13:59:29.38393] [6194] [trace] [ZShghqqC7kuD] Routing to a callback
[2026-03-16 13:59:29.38426] [6194] [debug] [ZShghqqC7kuD] Log::Any: Start timer to simulate an async operation in model 'B'
[2026-03-16 13:59:31.38926] [6194] [debug] [ZShghqqC7kuD] Log::Any: Logging message from model 'B'
[2026-03-16 13:59:31.38986] [6194] [trace] [ZShghqqC7kuD] 201 Created (2.00667s, 0.498/s)
=> The request id in the following log line is wrong; it should be pXXpxMu3Rci- instead of ZShghqqC7kuD
[2026-03-16 13:59:34.38953] [6194] [debug] [ZShghqqC7kuD] Log::Any: Logging message from model 'A'
[2026-03-16 13:59:34.39024] [6194] [trace] [pXXpxMu3Rci-] 201 Created (5.008702s, 0.200/s)
How could this problem be solved?
PS: If Log::Any cannot be used reliably in nonblocking code, maybe a warning should be added to its documentation.
We have started to use
Log::Any::Adapter::MojoLogin our Mojolicious application. In thestartup()method we are callingLog::Any::Adapter->set( 'MojoLog', logger => $app->log )Now we wanted to show the request-id as additional context information. The
MojoLogadapter isn't context aware: It doesn't implement thestructured()method. Instead of that the Mojolicious community has invented another way to add context (mojolicious/mojo#1404). This kind of context creates another child logger for each request based on the parent application level logger$app->log. To use this child logger we have called theset()method in each Mojolicious controller actionThe swapping of adapters leads to problems in nonblocking model/backend code.
How could this problem be solved?
PS: If Log::Any cannot be used reliably in nonblocking code, maybe a warning should be added to its documentation.