File tree Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Original file line number Diff line number Diff line change
1
+ use tracing:: { instrument, warn} ;
2
+ use tracing_subscriber:: { layer:: SubscriberExt , registry:: Registry } ;
3
+ use tracing_tree:: HierarchicalLayer ;
4
+
5
+ fn main ( ) {
6
+ let layer = HierarchicalLayer :: default ( )
7
+ . with_indent_lines ( true )
8
+ . with_indent_amount ( 2 )
9
+ . with_thread_names ( true )
10
+ . with_thread_ids ( true )
11
+ . with_targets ( true )
12
+ . with_wraparound ( 5 ) ;
13
+
14
+ let subscriber = Registry :: default ( ) . with ( layer) ;
15
+ tracing:: subscriber:: set_global_default ( subscriber) . unwrap ( ) ;
16
+
17
+ recurse ( 0 ) ;
18
+ }
19
+
20
+ #[ instrument]
21
+ fn recurse ( i : usize ) {
22
+ warn ! ( "boop" ) ;
23
+ if i > 20 {
24
+ warn ! ( "bop" ) ;
25
+ return ;
26
+ } else {
27
+ recurse ( i + 1 ) ;
28
+ }
29
+ warn ! ( "bop" ) ;
30
+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ pub struct Config {
26
26
pub render_thread_ids : bool ,
27
27
/// Whether to show thread names.
28
28
pub render_thread_names : bool ,
29
+ /// Specifies after how many indentation levels we will wrap back around to zero
30
+ pub wraparound : usize ,
29
31
}
30
32
31
33
impl Config {
@@ -58,6 +60,10 @@ impl Config {
58
60
}
59
61
}
60
62
63
+ pub fn with_wraparound ( self , wraparound : usize ) -> Self {
64
+ Self { wraparound, ..self }
65
+ }
66
+
61
67
pub ( crate ) fn prefix ( & self ) -> String {
62
68
let mut buf = String :: new ( ) ;
63
69
if self . render_thread_ids {
@@ -90,6 +96,7 @@ impl Default for Config {
90
96
targets : false ,
91
97
render_thread_ids : false ,
92
98
render_thread_names : false ,
99
+ wraparound : usize:: max_value ( ) ,
93
100
}
94
101
}
95
102
}
@@ -123,7 +130,7 @@ impl Buffers {
123
130
indent_block (
124
131
& mut self . current_buf ,
125
132
& mut self . indent_buf ,
126
- indent,
133
+ indent % config . wraparound ,
127
134
config. indent_amount ,
128
135
config. indent_lines ,
129
136
& config. prefix ( ) ,
Original file line number Diff line number Diff line change @@ -139,6 +139,16 @@ where
139
139
}
140
140
}
141
141
142
+ /// Resets the indentation to zero after `wraparound` indentation levels.
143
+ /// This is helpful if you expect very deeply nested spans as otherwise the indentation
144
+ /// just runs out of your screen.
145
+ pub fn with_wraparound ( self , wraparound : usize ) -> Self {
146
+ Self {
147
+ config : self . config . with_wraparound ( wraparound) ,
148
+ ..self
149
+ }
150
+ }
151
+
142
152
fn styled ( & self , style : Style , text : impl AsRef < str > ) -> String {
143
153
if self . config . ansi {
144
154
style. paint ( text. as_ref ( ) ) . to_string ( )
You can’t perform that action at this time.
0 commit comments