Cannot print log info from another thread of a pumpkin plugin #1816
Replies: 1 comment
|
There are two things happening here. First, For a native Pumpkin plugin, the clearest supported path is to clone the context into the thread and use ctx.init_log();
let log_ctx = Arc::clone(&ctx);
thread::spawn(move || {
let rt = Runtime::new().expect("failed to create web runtime");
rt.block_on(async move {
log_ctx.log("Starting web server on port 3000");
if let Err(error) = web::init_web_server().await {
log_ctx.log(format!("Web server stopped: {error}"));
}
});
});Second, the position of the original message matters. If web::init_web_server().await?;
tracing::info!("Web server is ready");logs only after the server exits, not after it starts. To report ready accurately, put the log inside So: remove the inner |
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to develop a pumpkin plugin. When I use the following code for my plugin, the web server is properly started on the port, but the log info just can't be printed to the console:
Anyone knows how to print a log from another thread?
All reactions