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 first.
Rust NixShell
crates.io (relastic)
cargo doc --open
cargo 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 does not allow blocking services to run in it's Tokio
runtime. We were unable to discover an easy for solution to create a globally available logging function, without being fully dependent on Rocket
dependencies. To use it with Rocket
thefore requires you to define your own Tokio
runtime instead of relying on Rocket
setup magic.
Here's how you may do it:
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();
}
You are welcome to reports bugs, contribute code or open issues.