@@ -7,9 +7,13 @@ use tokio_util::sync::CancellationToken;
7
7
#[ tokio:: main]
8
8
async fn main ( ) -> Result < ( ) > {
9
9
let dotenv_result = dotenvy:: dotenv ( ) ;
10
+ // TODO: remove me later when the launcher is fixed
11
+ amend_log_levels ( ) ;
12
+
10
13
env_logger:: builder ( )
11
14
. format_timestamp ( Some ( env_logger:: TimestampPrecision :: Millis ) )
12
15
. init ( ) ;
16
+ println ! ( "LOG_LEVEL: {}" , env:: var( "RUST_LOG" ) . unwrap( ) ) ;
13
17
if let Err ( e) = dotenv_result {
14
18
log:: warn!( "Could not load .env file: {}" , e) ;
15
19
}
@@ -142,3 +146,36 @@ async fn wait_for_termination(cancellation: CancellationToken) -> Result<()> {
142
146
cancellation. cancel ( ) ;
143
147
Ok ( ( ) )
144
148
}
149
+
150
+ /// Very CRUDE fix due to launcher log level bug
151
+ ///
152
+ /// TODO: remove me later when the launcher is fixed
153
+ pub fn amend_log_levels ( ) {
154
+ if let Ok ( rust_log) = std:: env:: var ( "RUST_LOG" ) {
155
+ let log_level = if rust_log. contains ( "dkn_compute=info" ) {
156
+ "info"
157
+ } else if rust_log. contains ( "dkn_compute=debug" ) {
158
+ "debug"
159
+ } else if rust_log. contains ( "dkn_compute=trace" ) {
160
+ "trace"
161
+ } else {
162
+ return ;
163
+ } ;
164
+
165
+ // check if it contains other log levels
166
+ let mut new_rust_log = rust_log. clone ( ) ;
167
+ if !rust_log. contains ( "dkn_p2p" ) {
168
+ new_rust_log = format ! ( "{},{}={}" , new_rust_log, "dkn_p2p" , log_level) ;
169
+ }
170
+ if !rust_log. contains ( "dkn_workflows" ) {
171
+ new_rust_log = format ! ( "{},{}={}" , new_rust_log, "dkn_workflows" , log_level) ;
172
+ }
173
+ std:: env:: set_var ( "RUST_LOG" , new_rust_log) ;
174
+ } else {
175
+ // TODO: use env_logger default function instead of this
176
+ std:: env:: set_var (
177
+ "RUST_LOG" ,
178
+ "none,dkn_compute=info,dkn_p2p=info,dkn_workflows=info" ,
179
+ ) ;
180
+ }
181
+ }
0 commit comments