Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created April 4, 2018 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitsuhiko/5188b99cea28886adf45c4c9d0295784 to your computer and use it in GitHub Desktop.
Save mitsuhiko/5188b99cea28886adf45c4c9d0295784 to your computer and use it in GitHub Desktop.
use std::panic;
extern crate sentry;
extern crate log;
pub struct Logger;
impl log::Log for Logger {
fn enabled(&self, metadata: &log::Metadata) -> bool {
metadata.level() <= log::max_level()
}
fn log(&self, record: &log::Record) {
if self.enabled(record.metadata()) {
// this captures a log record to the current context.
// If there is an active task it logs to it's context,
// otherwise it logs to a thread local thing.
sentry::capture_log_record(&record);
}
}
}
panic::set_hook(Box::new(|info| {
sentry::capture_exception(&info);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment