ecs-logger
A Rust logger compatible with Elastic Common Schema (ECS) Logging.
Features
- Configurable via the RUST_LOG environment variable.
- Uses env_logger under the hood.
- All logging is disabled except for the
error
level by default.
- Logs are written to stderr by default.
Installation
Add the following to your Cargo.toml
file:
[]
= "0.4"
= "1"
Documentation
Example
In the following examples we assume the binary is ./example
.
Basic logging
use ;
init;
debug!;
error!;
} }}}
} }}}
} }}}
More filtering config examples are available at env_logger’s documentation.
Extra Fields
You can add extra fields to the log output by using the extra_fields
module.
use extra_fields;
use Serialize;
init;
set_extra_fields.unwrap;
error!;
info!;
clear_extra_fields;
Custom logging
You need to add env_logger
to your Cargo.toml
for the following examples.
[]
= "0.4"
= "0.9"
= "1"
Write to stdout
use info;
// Initialize custom logger
builder
.format // Configure ECS logger
.target // Write to stdout
.init;
info!;
Configure log filters
use info;
// Initialize custom logger
builder
.parse_filters // Set filters
.format // Configure ECS logger
.init;
info!;
Default log fields
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Acknowledgment
The implementation of this software is based on env_logger, which is dual licenced as well.