Simple rust lib inspired by Serilog for application-wide logging:
Log to Elastic from Rust applications
Everyone. Do not use in production without first assessing the risks involved.
crates.io (relastic)
cargo doc --open
or docs.rscargo test
in the main folder to run tests```rs fn main() { let elasticconfig = match elasticconfig::ElasticConfig::new() { Ok(x) => x, Err(err) => panic!("Elastic not/improperly configured: {:?}", err), }; log::setupelasticlog( elastic_config, 100, );
/* ... */
log::flush();
} ```
Rocket by default does not allow blocking services to run in it's Tokio
runtime. It does have a functionality for running blocking tasks as async, but the logging service should hold precendence over it; If rocket panics, the logger should be able to log this before the application terminates.
Here's how you can setup relastic with Rocket:
rs
fn main() {
let elastic_config = match elastic_config::ElasticConfig::new() {
Ok(x) => x,
Err(err) => panic!("Elastic not/improperly configured: {:?}", err),
};
log::setup_elastic_log(
elastic_config,
100,
);
// Create multi-threaded tokio runtime for rocket
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
rocket_main().await;
});
log::flush();
}
This also makes it so that we don't have to rely on Rocket-specific dependencies.
rs
pub fn my_fn()
{
log::information(
"Got the following message: {message}",
HashMap::from([
("message", "Hello World!".to_string())
])
);
}
You are welcome to reports bugs, contribute code or open issues.