Crate sentry_log4rs
source ·Expand description
sentry-log4rs is a simple add-on for the log4rs logging framework to simplify integration with the Sentry application monitoring system.
Example usage
use log::error;
use log4rs;
use sentry_log4rs::SentryAppender;
fn main() {
log4rs::init_file("log4rs.yaml", SentryAppender::deserializers()).unwrap();
error!("Something went wrong!");
}
log4rs.yaml
file:
appenders:
sentry:
kind: sentry
encoder:
pattern: "{m}"
dsn: "YOUR_SENTRY_DSN_HERE"
threshold: error
root:
appenders:
- sentry
You can also constructing the configuration programmatically without using a config file:
use log::{LevelFilter, error};
use log4rs::{
config::{Appender, Config, Root},
encode::pattern::PatternEncoder,
};
use sentry_log4rs::SentryAppender;
fn main() {
let sentry = SentryAppender::builder()
.dsn("YOUR_SENTRY_DSN_HERE")
.threshold(LevelFilter::Error)
.encoder(Box::new(PatternEncoder::new("{m}")))
.build();
let config = Config::builder()
.appender(Appender::builder().build("sentry", Box::new(sentry)))
.build(
Root::builder()
.appender("sentry")
.build(LevelFilter::Info),
)
.unwrap();
log4rs::init_config(config).unwrap();
error!("Something went wrong!");
}
Structs
An appender which send log message to sentry.
A builder for
SentryAppender
s.Configuration for the sentry appender.
A deserializer for the
SentryAppender
.