Skip to content

Commit

Permalink
bug: send logging output to MozLog
Browse files Browse the repository at this point in the history
This fix routes logging messages through MozLog-json. The
`human_logs=TRUE` option returns human readable logs (like the previous
logging).

Closes #285
  • Loading branch information
jrconlin committed Oct 22, 2019
1 parent b9cd9ff commit b83429e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn init_logging(json: bool) -> ApiResult<()> {
let drain = slog_async::Async::new(drain).build().fuse();
slog::Logger::root(drain, slog_o!())
} else {
env_logger::init();
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::FullFormat::new(decorator).build().fuse();
let drain = slog_async::Async::new(drain).build().fuse();
Expand Down
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use log::{debug, info};
use serde_derive::Deserialize;

use syncstorage::{logging, server, settings};
use logging::init_logging;

const USAGE: &str = "
Usage: syncstorage [options]
Expand All @@ -21,7 +22,11 @@ struct Args {
}

fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();
let args: Args = Docopt::new(USAGE)
.and_then(|d| d.deserialize())
.unwrap_or_else(|e| e.exit());
let settings = settings::Settings::with_env_and_config_file(&args.flag_config)?;
init_logging(!settings.human_logs).expect("Logging failed to initialize");
debug!("Starting up...");
// Set SENTRY_DSN environment variable to enable Sentry.
// Avoid its default reqwest transport for now due to issues w/
Expand All @@ -38,10 +43,6 @@ fn main() -> Result<(), Box<dyn Error>> {
sentry::integrations::panic::register_panic_handler();
}

let args: Args = Docopt::new(USAGE)
.and_then(|d| d.deserialize())
.unwrap_or_else(|e| e.exit());
let settings = settings::Settings::with_env_and_config_file(&args.flag_config)?;
// Setup and run the server
let banner = settings.banner();
let sys = server::Server::with_settings(settings).unwrap();
Expand Down

0 comments on commit b83429e

Please sign in to comment.