Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
934 changes: 923 additions & 11 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde_derive = "1.0"
serde_json = "1.0"
diesel_migrations = "1.2.0"
exitfailure = "0.4.1"
sentry = "0.6.0"

[dependencies.chrono]
version = "0.4"
Expand Down
1 change: 1 addition & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ apps:
device-checkout:
plugs:
- network-bind
- network
command: bin/device-checkout --templates ${SNAP}/usr/share/device-checkout/templates --database ${SNAP_DATA}/devices.db
daemon: simple
restart-condition: always
1 change: 1 addition & 0 deletions src/bin/device-checkout.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern crate device_checkout_lib;

use device_checkout_lib::*;
use failure::ResultExt;

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub extern crate clap;
pub extern crate rocket;
pub extern crate rocket_contrib;
#[macro_use]
pub extern crate sentry;
#[macro_use]
pub extern crate serde_derive;
pub extern crate serde;
pub extern crate serde_json;
Expand Down
8 changes: 8 additions & 0 deletions src/utils/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn parse(matches: &clap::ArgMatches) -> Result<types::Settings, clap::Error> {
})?
}
let quiet = matches.is_present("quiet");
let reporting = !matches.is_present("no-reporting");
let timestamp = match matches.value_of("timestamp") {
Some("ns") => types::Timestamp::Nanosecond,
Some("ms") => types::Timestamp::Microsecond,
Expand Down Expand Up @@ -46,6 +47,7 @@ fn parse(matches: &clap::ArgMatches) -> Result<types::Settings, clap::Error> {
timestamp,
port,
template_dir,
reporting,
database_url: database.to_string(),
..Default::default()
})
Expand All @@ -67,6 +69,12 @@ fn matcher<'a, 'b>() -> clap::App<'a, 'b> {
.long("quiet")
.help("Silence all output"),
)
.arg(
clap::Arg::with_name("no-reporting")
.short("r")
.long("no-reporting")
.help("Don't report errors to sentry.io"),
)
.arg(
clap::Arg::with_name("timestamp")
.short("t")
Expand Down
21 changes: 20 additions & 1 deletion src/utils/logging.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use sentry;
use stderrlog;
use utils::types;

Expand All @@ -11,7 +12,25 @@ pub fn configure_logger(config: &types::Settings) {
.verbosity(config.verbosity)
.timestamp(config.timestamp);

logger.init().unwrap();
if config.reporting {
sentry::init((
"https://[email protected]/1240440",
sentry::ClientOptions {
release: sentry_crate_release!(),
..Default::default()
},
));

sentry::integrations::panic::register_panic_handler();

let options = sentry::integrations::log::LoggerOptions {
..Default::default()
};

sentry::integrations::log::init(Some(Box::new(logger)), options);
} else {
logger.init().unwrap();
}
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions src/utils/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub use stderrlog::Timestamp;
pub struct Settings {
pub verbosity: usize,
pub quiet: bool,
pub reporting: bool,
pub timestamp: Timestamp,
pub module_path: Option<String>,
pub template_dir: Option<String>,
Expand All @@ -25,6 +26,7 @@ impl Default for Settings {
Settings {
verbosity: 0,
quiet: false,
reporting: true,
timestamp: Timestamp::Off,
module_path: None,
template_dir: None,
Expand Down