@@ -258,56 +258,58 @@ pub fn init() {
258258 } ;
259259
260260 // Check if message contains JSON-like structure that can be extracted and formatted.
261- if msg. len ( ) > 100 && ( ts == log:: Level :: Debug || ts == log:: Level :: Trace )
262- && let ( Some ( start) , Some ( end) ) = ( msg. find ( '{' ) , msg. rfind ( '}' ) ) {
263- let json_part = & msg[ start..=end] ;
264-
265- let regex = regex:: Regex :: new ( r#"String\("([^"]*)"\)"# ) . ok ( ) ;
266-
267- // Strategy 1: strict conversion of common Rust debug wrappers.
268- let mut attempts: Vec < String > = Vec :: with_capacity ( 2 ) ;
269- let mut cleaned = json_part. replace ( "Object " , "" ) ;
270- if let Some ( re) = & regex {
271- cleaned = re. replace_all ( & cleaned, r#""$1""# ) . to_string ( ) ;
272- }
273- attempts. push ( cleaned) ;
274-
275- // Strategy 2: aggressive conversion fallback for odd wrapper nesting.
276- let aggressive = json_part
277- . replace ( "Object " , "" )
278- . replace ( "String(\" " , "\" " )
279- . replace ( "\" )" , "\" " ) ;
280- attempts. push ( aggressive) ;
281-
282- for json_clean in attempts {
283- if let Ok ( value) = serde_json:: from_str :: < serde_json:: Value > ( & json_clean)
284- && let Ok ( pretty) = serde_json:: to_string_pretty ( & value) {
285- let label = clean_label ( & msg[ ..start] ) ;
286- let header =
287- format ! ( "[{}] [{}] {:5} [{}]: {} " , date, time, ts, source, label) ;
288- let lines: Vec < & str > = pretty. lines ( ) . collect ( ) ;
289- return writeln ! (
290- buf,
291- "{}{}" ,
292- header,
293- lines. join( & format!( "\n {}" , " " . repeat( header. len( ) ) ) )
294- ) ;
295- }
261+ if msg. len ( ) > 100
262+ && ( ts == log:: Level :: Debug || ts == log:: Level :: Trace )
263+ && let ( Some ( start) , Some ( end) ) = ( msg. find ( '{' ) , msg. rfind ( '}' ) )
264+ {
265+ let json_part = & msg[ start..=end] ;
266+
267+ let regex = regex:: Regex :: new ( r#"String\("([^"]*)"\)"# ) . ok ( ) ;
268+
269+ // Strategy 1: strict conversion of common Rust debug wrappers.
270+ let mut attempts: Vec < String > = Vec :: with_capacity ( 2 ) ;
271+ let mut cleaned = json_part. replace ( "Object " , "" ) ;
272+ if let Some ( re) = & regex {
273+ cleaned = re. replace_all ( & cleaned, r#""$1""# ) . to_string ( ) ;
274+ }
275+ attempts. push ( cleaned) ;
276+
277+ // Strategy 2: aggressive conversion fallback for odd wrapper nesting.
278+ let aggressive = json_part
279+ . replace ( "Object " , "" )
280+ . replace ( "String(\" " , "\" " )
281+ . replace ( "\" )" , "\" " ) ;
282+ attempts. push ( aggressive) ;
283+
284+ for json_clean in attempts {
285+ if let Ok ( value) = serde_json:: from_str :: < serde_json:: Value > ( & json_clean)
286+ && let Ok ( pretty) = serde_json:: to_string_pretty ( & value)
287+ {
288+ let label = clean_label ( & msg[ ..start] ) ;
289+ let header = format ! ( "[{}] [{}] {:5} [{}]: {} " , date, time, ts, source, label) ;
290+ let lines: Vec < & str > = pretty. lines ( ) . collect ( ) ;
291+ return writeln ! (
292+ buf,
293+ "{}{}" ,
294+ header,
295+ lines. join( & format!( "\n {}" , " " . repeat( header. len( ) ) ) )
296+ ) ;
296297 }
297-
298- // Fallback: non-JSON Rust debug structs (e.g., RemoteRelease { ... })
299- let label = clean_label ( & msg[ ..start] ) ;
300- let pretty = format_braced ( json_part) ;
301- let header = format ! ( "[{}] [{}] {:5} [{}]: {} " , date, time, ts, source, label) ;
302- let lines: Vec < & str > = pretty. lines ( ) . collect ( ) ;
303- return writeln ! (
304- buf,
305- "{}{}" ,
306- header,
307- lines. join( & format!( "\n {}" , " " . repeat( header. len( ) ) ) )
308- ) ;
309298 }
310299
300+ // Fallback: non-JSON Rust debug structs (e.g., RemoteRelease { ... })
301+ let label = clean_label ( & msg[ ..start] ) ;
302+ let pretty = format_braced ( json_part) ;
303+ let header = format ! ( "[{}] [{}] {:5} [{}]: {} " , date, time, ts, source, label) ;
304+ let lines: Vec < & str > = pretty. lines ( ) . collect ( ) ;
305+ return writeln ! (
306+ buf,
307+ "{}{}" ,
308+ header,
309+ lines. join( & format!( "\n {}" , " " . repeat( header. len( ) ) ) )
310+ ) ;
311+ }
312+
311313 writeln ! ( buf, "[{}] [{}] {:5} [{}]: {}" , date, time, ts, source, msg)
312314 } ) ;
313315
0 commit comments