@@ -5,24 +5,25 @@ use std::sync::Arc;
5
5
use std:: time:: Duration ;
6
6
7
7
use again:: RetryPolicy ;
8
+ use blob_archiver_beacon:: beacon_client;
9
+ use blob_archiver_beacon:: beacon_client:: BeaconClientEth2 ;
10
+ use blob_archiver_storage:: fs:: FSStorage ;
11
+ use blob_archiver_storage:: s3:: { S3Config , S3Storage } ;
12
+ use blob_archiver_storage:: storage;
13
+ use blob_archiver_storage:: storage:: { Storage , StorageType } ;
8
14
use clap:: Parser ;
9
15
use ctrlc:: set_handler;
10
16
use eth2:: types:: { BlockId , Hash256 } ;
11
17
use eth2:: { BeaconNodeHttpClient , SensitiveUrl , Timeouts } ;
18
+ use eyre:: eyre;
12
19
use serde:: { Deserialize , Serialize } ;
13
20
use tokio:: sync:: Mutex ;
14
21
use tracing:: log:: error;
22
+ use tracing:: Level ;
15
23
use tracing_appender:: rolling:: { RollingFileAppender , Rotation } ;
24
+ use tracing_subscriber:: fmt;
25
+ use tracing_subscriber:: fmt:: writer:: MakeWriterExt ;
16
26
use tracing_subscriber:: layer:: SubscriberExt ;
17
- use tracing_subscriber:: util:: SubscriberInitExt ;
18
- use tracing_subscriber:: { fmt, EnvFilter } ;
19
-
20
- use blob_archiver_beacon:: beacon_client;
21
- use blob_archiver_beacon:: beacon_client:: BeaconClientEth2 ;
22
- use blob_archiver_storage:: fs:: FSStorage ;
23
- use blob_archiver_storage:: s3:: { S3Config , S3Storage } ;
24
- use blob_archiver_storage:: storage;
25
- use blob_archiver_storage:: storage:: { Storage , StorageType } ;
26
27
27
28
use crate :: archiver:: { Archiver , Config , STARTUP_FETCH_BLOB_MAXIMUM_RETRIES } ;
28
29
@@ -119,18 +120,6 @@ pub fn setup_tracing(
119
120
log_dir : Option < PathBuf > ,
120
121
rotation : Option < Rotation > ,
121
122
) -> eyre:: Result < ( ) > {
122
- let filter = match verbose {
123
- 0 => EnvFilter :: new ( "error" ) ,
124
- 1 => EnvFilter :: new ( "warn" ) ,
125
- 2 => EnvFilter :: new ( "info" ) ,
126
- 3 => EnvFilter :: new ( "debug" ) ,
127
- _ => EnvFilter :: new ( "trace" ) ,
128
- } ;
129
-
130
- let subscriber = tracing_subscriber:: registry ( )
131
- . with ( EnvFilter :: from_default_env ( ) )
132
- . with ( filter) ;
133
-
134
123
if let Some ( log_dir) = log_dir {
135
124
fs:: create_dir_all ( & log_dir)
136
125
. map_err ( |e| eyre:: eyre!( "Failed to create log directory: {}" , e) ) ?;
@@ -141,19 +130,43 @@ pub fn setup_tracing(
141
130
"blob-archiver.log" ,
142
131
) ;
143
132
let ( non_blocking, _guard) = tracing_appender:: non_blocking ( file_appender) ;
144
- let file_layer = fmt:: layer ( ) . with_writer ( non_blocking) . with_ansi ( false ) ;
145
-
146
- subscriber
147
- . with ( file_layer)
148
- . with ( fmt:: layer ( ) . with_writer ( std:: io:: stdout) )
149
- . try_init ( ) ?;
133
+ let file_layer = fmt:: layer ( )
134
+ . with_writer ( non_blocking. with_max_level ( match verbose {
135
+ 0 => Level :: ERROR ,
136
+ 1 => Level :: WARN ,
137
+ 2 => Level :: INFO ,
138
+ 3 => Level :: DEBUG ,
139
+ _ => Level :: TRACE ,
140
+ } ) )
141
+ . with_ansi ( false ) ;
142
+
143
+ let subscriber =
144
+ tracing_subscriber:: registry ( )
145
+ . with ( file_layer)
146
+ . with (
147
+ fmt:: layer ( ) . with_writer ( std:: io:: stdout. with_max_level ( match verbose {
148
+ 0 => Level :: ERROR ,
149
+ 1 => Level :: WARN ,
150
+ 2 => Level :: INFO ,
151
+ 3 => Level :: DEBUG ,
152
+ _ => Level :: TRACE ,
153
+ } ) ) ,
154
+ ) ;
155
+ tracing:: subscriber:: set_global_default ( subscriber) . map_err ( |e| eyre ! ( e) ) ?;
156
+ Ok ( ( ) )
150
157
} else {
151
- subscriber
152
- . with ( fmt:: layer ( ) . with_writer ( std:: io:: stdout) )
153
- . try_init ( ) ?;
158
+ let subscriber = tracing_subscriber:: registry ( ) . with ( fmt:: layer ( ) . with_writer (
159
+ std:: io:: stdout. with_max_level ( match verbose {
160
+ 0 => Level :: ERROR ,
161
+ 1 => Level :: WARN ,
162
+ 2 => Level :: INFO ,
163
+ 3 => Level :: DEBUG ,
164
+ _ => Level :: TRACE ,
165
+ } ) ,
166
+ ) ) ;
167
+ tracing:: subscriber:: set_global_default ( subscriber) . map_err ( |e| eyre ! ( e) ) ?;
168
+ Ok ( ( ) )
154
169
}
155
-
156
- Ok ( ( ) )
157
170
}
158
171
159
172
#[ derive( Parser , Serialize ) ]
0 commit comments