-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: send all logs unedited to trace
- Loading branch information
1 parent
603660b
commit b41e9cf
Showing
8 changed files
with
129 additions
and
23 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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use rocket::Config; | ||
|
||
#[cfg(feature = "trace")] | ||
pub mod subscriber; | ||
|
||
pub trait PaintExt: Sized { | ||
fn emoji(self) -> yansi::Painted<Self>; | ||
} | ||
|
||
impl PaintExt for &str { | ||
/// Paint::masked(), but hidden on Windows due to broken output. See #1122. | ||
fn emoji(self) -> yansi::Painted<Self> { | ||
#[cfg(windows)] { yansi::Paint::new("").mask() } | ||
#[cfg(not(windows))] { yansi::Paint::new(self).mask() } | ||
} | ||
} | ||
|
||
macro_rules! declare_macro { | ||
($($name:ident),*) => ( | ||
$(declare_macro!([$] $name);)* | ||
); | ||
|
||
([$d:tt] $name:ident) => ( | ||
#[macro_export] | ||
macro_rules! $name { | ||
($d ($t:tt)*) => ({ | ||
#[allow(unused_imports)] | ||
use $crate::trace::PaintExt as _; | ||
|
||
$crate::tracing::event!($crate::tracing::Level::INFO, $d ($t)*); | ||
}) | ||
} | ||
); | ||
} | ||
|
||
declare_macro!(log, log_, launch_info, launch_info_, launch_meta, launch_meta_, | ||
error, error_, info, info_, trace, trace_, debug, debug_, warn, warn_); | ||
|
||
pub fn init(_config: &Config) { | ||
#[cfg(feature = "trace")] | ||
subscriber::init(_config); | ||
} |
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,66 @@ | ||
use std::sync::OnceLock; | ||
|
||
use tracing::{Level, Subscriber}; | ||
use tracing::level_filters::LevelFilter; | ||
use tracing_subscriber::prelude::*; | ||
use tracing_subscriber::registry::LookupSpan; | ||
use tracing_subscriber::{reload, filter, Layer, Registry}; | ||
use yansi::{Condition, Paint, Painted}; | ||
|
||
use crate::Config; | ||
|
||
pub trait PaintExt: Sized { | ||
fn emoji(self) -> Painted<Self>; | ||
} | ||
|
||
impl PaintExt for &str { | ||
/// Paint::masked(), but hidden on Windows due to broken output. See #1122. | ||
fn emoji(self) -> Painted<Self> { | ||
#[cfg(windows)] { Paint::new("").mask() } | ||
#[cfg(not(windows))] { Paint::new(self).mask() } | ||
} | ||
} | ||
|
||
pub fn filter_layer(level: Level) -> filter::Targets { | ||
filter::Targets::new() | ||
.with_default(level) | ||
.with_target("rustls", LevelFilter::OFF) | ||
.with_target("hyper", LevelFilter::OFF) | ||
} | ||
|
||
pub fn fmt_layer<S: Subscriber + for<'span> LookupSpan<'span>>() -> impl Layer<S> { | ||
let layer = tracing_subscriber::fmt::layer(); | ||
|
||
#[cfg(not(test))] { layer } | ||
#[cfg(test)] { layer.with_test_writer() } | ||
} | ||
|
||
pub(crate) fn init(config: &Config) { | ||
static HANDLE: OnceLock<reload::Handle<filter::Targets, Registry>> = OnceLock::new(); | ||
|
||
// FIXME: Read the true level from `config`. | ||
let level = Level::INFO; | ||
|
||
// Always disable colors if requested or if the stdout/err aren't TTYs. | ||
let should_color = match config.cli_colors { | ||
crate::config::CliColors::Always => Condition::ALWAYS, | ||
crate::config::CliColors::Auto => Condition::DEFAULT, | ||
crate::config::CliColors::Never => Condition::NEVER, | ||
}; | ||
|
||
let (filter, reload_handle) = reload::Layer::new(filter_layer(level)); | ||
let result = tracing_subscriber::registry() | ||
.with(filter) | ||
.with(fmt_layer()) | ||
.try_init(); | ||
|
||
if result.is_ok() { | ||
assert!(HANDLE.set(reload_handle).is_ok()); | ||
yansi::whenever(should_color); | ||
} else if let Some(handle) = HANDLE.get() { | ||
assert!(handle.modify(|filter| *filter = filter_layer(level)).is_ok()); | ||
yansi::whenever(should_color); | ||
} else { | ||
yansi::disable() | ||
} | ||
} |
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