This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch to slog-mozlog-json/mozsvc-common for logging
limit the max log levels from external crates via the log crate (some deps like tokio-core are too verbose), allowing travis tests to run in rustc debug mode also fix the default crypto_key setting (expects a String) Closes #1247
- Loading branch information
Showing
12 changed files
with
110 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::io; | ||
|
||
use errors::Result; | ||
|
||
use mozsvc_common::{aws::get_ec2_instance_id, get_hostname}; | ||
use slog::{self, Drain}; | ||
use slog_async; | ||
use slog_mozlog_json::MozLogJson; | ||
use slog_scope; | ||
use slog_stdlog; | ||
use slog_term; | ||
|
||
pub fn init_logging(json: bool) -> Result<()> { | ||
let logger = if json { | ||
let hostname = get_ec2_instance_id() | ||
.map(&str::to_owned) | ||
.or_else(get_hostname) | ||
.ok_or_else(|| "Couldn't get_hostname")?; | ||
|
||
let drain = MozLogJson::new(io::stdout()) | ||
.logger_name(format!( | ||
"{}-{}", | ||
env!("CARGO_PKG_NAME"), | ||
env!("CARGO_PKG_VERSION") | ||
)) | ||
.msg_type(format!("{}:log", env!("CARGO_PKG_NAME"))) | ||
.hostname(hostname) | ||
.build() | ||
.fuse(); | ||
let drain = slog_async::Async::new(drain).build().fuse(); | ||
slog::Logger::root(drain, slog_o!()) | ||
} else { | ||
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(); | ||
slog::Logger::root(drain, slog_o!()) | ||
}; | ||
// XXX: cancel slog_scope's NoGlobalLoggerSet for now, it's difficult to | ||
// prevent it from potentially panicing during tests. reset_logging resets | ||
// the global logger during shutdown anyway: | ||
// https://github.com/slog-rs/slog/issues/169 | ||
slog_scope::set_global_logger(logger).cancel_reset(); | ||
slog_stdlog::init().ok(); | ||
Ok(()) | ||
} | ||
|
||
pub fn reset_logging() { | ||
let logger = slog::Logger::root(slog::Discard, o!()); | ||
slog_scope::set_global_logger(logger).cancel_reset(); | ||
} |
Oops, something went wrong.