Crates.io | tracing-logstash |
lib.rs | tracing-logstash |
version | 0.7.0 |
source | src |
created_at | 2021-02-05 15:48:28.210556 |
updated_at | 2024-01-08 19:59:18.555548 |
description | Minimal library to output logstash formatted events |
homepage | https://github.com/gsson/tracing-logstash |
repository | |
max_upload_size | |
id | 351160 |
size | 40,372 |
The absolute minimum amount of code I could get away with for writing tracing messages/logs in the https://github.com/logstash/logstash-logback-encoder#standard-fields format.
Currently built for use in a single application with a single log consumer.
You can include this library in your Cargo.toml file:
[dependencies]
tracing-logstash = "0.6.1"
fn main() {
let logger = tracing_logstash::Layer::default()
.event_format(tracing_logstash::logstash::LogstashFormat::default()
.with_constants(vec![
("service.name", "tracing-logstash".to_owned()),
])
);
let env_filter = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("info"))
.unwrap();
let collector = Registry::default().with(logger).with(env_filter);
tracing::subscriber::set_global_default(collector).unwrap();
tracing::info!("Hello, world!");
}
https://github.com/logstash/logstash-logback-encoder#standard-fields
{
"@version": "1",
"@timestamp": "2023-09-14T09:34:17.233512Z",
"thread_name": "tokio-runtime-worker",
"logger_name": "hyper",
"level": "INFO",
"level_value": 5,
"message": "tracing crate macro",
"some_tag": 43,
"service.name": "tracing-logstash"
}
This library is distributed under the terms of the MIT License. See the LICENSE file for details.