Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nocduro/syslog5424
A Rust trait based formatter for syslog RFC5424
https://github.com/nocduro/syslog5424
logging rust-crate rust-trait syslog
Last synced: 3 days ago
JSON representation
A Rust trait based formatter for syslog RFC5424
- Host: GitHub
- URL: https://github.com/nocduro/syslog5424
- Owner: nocduro
- License: mit
- Created: 2018-09-01T01:10:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-07T01:43:09.000Z (almost 3 years ago)
- Last Synced: 2025-01-02T01:42:44.513Z (17 days ago)
- Topics: logging, rust-crate, rust-trait, syslog
- Language: Rust
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# ⚠This crate will not be maintained or updated⚠
I no longer use syslog for my logging, I recommend trying out `tracing` or `opentelemetry` instead# `syslog5424` - trait based syslog 5424 message formatting
[![Build Status](https://dev.azure.com/nocduro/syslog5424/_apis/build/status/nocduro.syslog5424)](https://dev.azure.com/nocduro/syslog5424/_build/latest?definitionId=3)
[![crates.io badge](https://img.shields.io/crates/v/syslog5424.svg)](https://crates.io/crates/syslog5424)This crate provides a way for data to be formatted as an RFC5424 (or RFC5425) message and written to any type that implements `Write`.
Any type that implements the `Rfc5424Data` trait can be formatted.## Documentation
https://docs.rs/syslog5424## `slog` implementation
This crate was originally made as a way to have `slog` format its log messages as rfc 5424.The implementation for that is here: https://github.com/nocduro/slog-syslog5424
## Example
This example shows a minimal implementation of the `Rfc5424Data` trait.
```rust
#[derive(Debug)]
pub struct Rfc5424Message<'a> {
pub severity: Severity,
pub structured_data: Option>,
pub message: Option,
}impl<'a> Rfc5424Data for Rfc5424Message<'a> {
fn severity(&self) -> Severity {
self.severity
}fn timestamp(&self) -> Option {
None
}fn structured_data(&self) -> Option {
self.structured_data.clone()
}fn message(&self) -> Option {
self.message.clone()
}
}fn main() {
// create the formatter struct
let formatter = Rfc5424Builder::new("enterprise_id", Facility::User)
.hostname("api_server_1").unwrap()
.app_name("api").unwrap()
.build();
// create a message to be formatted
let mut hmap: StructuredData = HashMap::new();
hmap.insert(
"custom",
vec![
("id".into(), "54".into()),
("progress".into(), "complete".into()),
],
);let msg = Rfc5424Message {
severity: Severity::Error,
structured_data: Some(hmap),
message: Some(Message::Text("sample message. Hello there!".into())),
};// run the formatter
let mut out = Vec::new();
formatter.format(&mut out, &msg).unwrap();
println!("log: {}", String::from_utf8(out).unwrap());
}
```## OS support
Should work on any system where `std` is available, the OS specifics are introduced by the user when picking which `Writer` to use.## License
MIT (see LICENSE)