[−][src]Crate serde_gelf
Serde GELF
The Graylog Extended Log Format (GELF) is a log format that avoids the shortcomings of classic log formats. GELF is a great choice for logging from within applications. There are libraries and appenders for many programming languages and logging frameworks so it is easy to implement. You could use GELF to send every exception as a log message to your Graylog cluster.
{
"facility": "src",
"file": "examples/src/main.rs",
"host": "myDesk",
"level": 1,
"_levelname": "Alert",
"line": 21,
"short_message": "Message with the default level",
"timestamp": 1554907321.6123526,
"version": "1.1"
}
Quickstart
You can start using it by first adding it to your Cargo.toml
:
[dependencies]
serde_derive = "1.0"
serde_gelf = "0.1"
Then, create a structure which implement the serde::Serialize
trait:
#[macro_use] extern crate serde_derive; extern crate serde_gelf; #[derive(Serialize)] struct Foo { a: u32, b: String, } fn main() { let foo = Foo { a: 15, b: "hello".into() }; println!("{:?}", serde_gelf::to_flat_dict(&foo).unwrap()); }
Output:
{"_a": U32(15), "_b": String("hello")}
Macros
gelf_record | Construct a |
Structs
GelfRecord | Structure which represent a log record. |
Enums
GelfLevel | An enum representing the record level which is equal to the standard syslog levels. |
Traits
GelfRecordBuilder | Builder for |
GelfRecordGetter | Trait to access to |
GelfRecordSetter | Trait to update |
Functions
to_flat_dict | Transform any serializable object into a single level hashmap of key / value. |