Expand description
A GELF library for Rust.
The library can be used either as a standalone logging library
or it can be used as a logging-subsystem with the
log
-crate
§Use
In general you should only use this crate in applications. Libraries should
only develop against log
.
This then allows applications to use a custom logging-framework (like gelf
)
to do the actual logging.
§Standalone
Standalone usage is recommended if the lightweight log
-crate’s features
are not sufficient. In this case you need to inject/use an instance of
gelf::Logger
directly. This allows for sending custom built gelf::Message
-objects.
These messages can use all bells and whistles of GELF.
§Example
extern crate gelf;
use gelf::{Logger, UdpBackend, Message, Level};
pub fn main() {
// Set up logging
let backend = UdpBackend::new("127.0.0.1:12201")
.expect("Failed to create UDP backend");
let mut logger = Logger::new(Box::new(backend))
.expect("Failed to determine hostname");
logger.set_default_metadata(String::from("facility"),
String::from("example-rust-app"));
// Create a (complex) message
let mut message = Message::new(String::from("Custom message!"));
message
.set_full_message(String::from("The full message text is more descriptive"))
.set_metadata("foo", String::from("bar")).unwrap()
.set_metadata("baz", String::from("bat")).unwrap();
// Log it
logger.log_message(message);
}
§With log
Usage with log
allows to log easily with the help of its macros. There is no need to
inject or access the logger object anywhere in your application.
All the context information (line, file, etc.) the log
-crate provides is added as metadata
to the logged GELF message.
#[macro_use]
extern crate log;
extern crate gelf;
use gelf::{Logger, UdpBackend, Message, Level};
use log::LevelFilter;
pub fn main() {
let backend = UdpBackend::new("127.0.0.1:12201")
.expect("Failed to create UDP backend");
// Init logging system
let logger = Logger::new(Box::new(backend))
.expect("Failed to determine hostname");
logger.install(LevelFilter::Trace)
.expect("Failed to install logger");
info!("Descend into our program!");
somewhere()
}
pub fn somewhere() {
trace!("Trace something here!");
over::the_rainbow();
}
mod over {
pub fn the_rainbow() {
error!("Oh well...");
}
}
Structs§
- Logger
- Logger for sending log-messages
- Message
- Message is thre representation of a GELF message.
- Null
Backend - The
NullBackend
is a utility backend which discards all messages - TcpBackend
- TcpBackend is a simple GELF over TCP backend.
- UdpBackend
- UdpBackend is the default and standard GELF backend
- Wire
Message - WireMessage is the representation of a fully assembled GELF message
Enums§
- Chunk
Size - ChunkSize is a value type representing the size of a message-chunk
- Error
- Level
- GELF’s representation of an error level
- Message
Compression - MessageCompression represents all possible compression algorithms in GELF.
Traits§
- Backend
- A trait for a GELF backend