Skip to content

Commit b26b3c1

Browse files
authored
chore: update to tracing-subscriber 0.3 (#40)
1 parent 4f5635e commit b26b3c1

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readme = "README.md"
1010

1111
[dependencies]
1212
tracing-core = "0.1"
13-
tracing-subscriber = { version = "0.2", default-features = false, features = ["registry", "fmt"] }
13+
tracing-subscriber = { version = "0.3", default-features = false, features = ["registry", "fmt", "std"] }
1414
ansi_term = "0.12"
1515
atty = "0.2"
1616
tracing-log = { version = "0.1", optional = true }

src/lib.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing_log::NormalizeEvent;
1818
use tracing_subscriber::{
1919
fmt::MakeWriter,
2020
layer::{Context, Layer},
21-
registry::LookupSpan,
21+
registry::{self, LookupSpan},
2222
};
2323

2424
pub(crate) struct Data {
@@ -46,7 +46,7 @@ impl Visit for Data {
4646
#[derive(Debug)]
4747
pub struct HierarchicalLayer<W = fn() -> io::Stdout>
4848
where
49-
W: MakeWriter + 'static,
49+
W: for<'writer> MakeWriter<'writer> + 'static,
5050
{
5151
make_writer: W,
5252
bufs: Mutex<Buffers>,
@@ -77,7 +77,7 @@ impl HierarchicalLayer<fn() -> io::Stdout> {
7777

7878
impl<W> HierarchicalLayer<W>
7979
where
80-
W: MakeWriter + 'static,
80+
W: for<'writer> MakeWriter<'writer> + 'static,
8181
{
8282
/// Enables terminal colors, boldness and italics.
8383
pub fn with_ansi(self, ansi: bool) -> Self {
@@ -89,7 +89,7 @@ where
8989

9090
pub fn with_writer<W2>(self, make_writer: W2) -> HierarchicalLayer<W2>
9191
where
92-
W2: MakeWriter + 'static,
92+
W2: for<'writer> MakeWriter<'writer>,
9393
{
9494
HierarchicalLayer {
9595
make_writer,
@@ -221,10 +221,14 @@ where
221221
let bufs = &mut *guard;
222222
let mut current_buf = &mut bufs.current_buf;
223223

224-
// todo(david): i'm going to keep this for a bit since there's an odd discrepancy in counting
225-
// that i don't want to resolve rn lol
226-
#[allow(deprecated)]
227-
let indent = ctx.scope().count();
224+
let indent = ctx
225+
.lookup_current()
226+
.as_ref()
227+
.map(registry::SpanRef::scope)
228+
.map(registry::Scope::from_root)
229+
.into_iter()
230+
.flatten()
231+
.count();
228232

229233
if self.config.verbose_entry || matches!(style, SpanMode::Open { .. } | SpanMode::Event) {
230234
if self.config.targets {
@@ -274,9 +278,9 @@ where
274278
impl<S, W> Layer<S> for HierarchicalLayer<W>
275279
where
276280
S: Subscriber + for<'span> LookupSpan<'span> + fmt::Debug,
277-
W: MakeWriter + 'static,
281+
W: for<'writer> MakeWriter<'writer> + 'static,
278282
{
279-
fn new_span(&self, attrs: &Attributes, id: &Id, ctx: Context<S>) {
283+
fn on_new_span(&self, attrs: &Attributes, id: &Id, ctx: Context<S>) {
280284
let data = Data::new(attrs);
281285
let span = ctx.span(id).expect("in new_span but span does not exist");
282286
span.extensions_mut().insert(data);
@@ -297,7 +301,7 @@ where
297301

298302
fn on_event(&self, event: &Event<'_>, ctx: Context<S>) {
299303
let mut guard = self.bufs.lock().unwrap();
300-
let mut bufs = &mut *guard;
304+
let bufs = &mut *guard;
301305
let mut event_buf = &mut bufs.current_buf;
302306

303307
// printing the indentation
@@ -362,10 +366,7 @@ where
362366
.expect("Unable to write to buffer");
363367
}
364368

365-
let mut visitor = FmtEvent {
366-
comma: false,
367-
bufs: &mut bufs,
368-
};
369+
let mut visitor = FmtEvent { comma: false, bufs };
369370
event.record(&mut visitor);
370371
visitor
371372
.bufs

0 commit comments

Comments
 (0)