11//! Custom JSON formatter and writer for use in logging.
22
3- use std:: { borrow:: Cow , collections:: BTreeMap , fmt, io, env , sync :: LazyLock , marker :: PhantomData } ;
3+ use std:: { borrow:: Cow , collections:: BTreeMap , env , fmt, io, marker :: PhantomData , sync :: LazyLock } ;
44
55use regex:: Regex ;
66use serde:: { ser:: SerializeMap , Deserialize , Serialize , Serializer } ;
@@ -17,9 +17,8 @@ use tracing_subscriber::{
1717 registry:: { LookupSpan , SpanRef } ,
1818} ;
1919
20- static ENV_VAR_REGEX : LazyLock < Regex > = LazyLock :: new ( || {
21- Regex :: new ( r"\$([A-Za-z_][A-Za-z0-9_]*)" ) . unwrap ( )
22- } ) ;
20+ static ENV_VAR_REGEX : LazyLock < Regex > =
21+ LazyLock :: new ( || Regex :: new ( r"\$([A-Za-z_][A-Za-z0-9_]*)" ) . unwrap ( ) ) ;
2322
2423/// Custom names JSON keys.
2524#[ derive( Clone , Debug , Deserialize , PartialEq , Serialize ) ]
@@ -439,13 +438,19 @@ impl<T> ExtensibleJsonFormat<T> {
439438 }
440439
441440 /// Add static fields to generated JSON objects.
442- pub ( crate ) fn with_static_fields ( self , mut static_fields : BTreeMap < String , Value > , parse_env : bool ) -> Self {
441+ pub ( crate ) fn with_static_fields (
442+ self ,
443+ mut static_fields : BTreeMap < String , Value > ,
444+ parse_env : bool ,
445+ ) -> Self {
443446 if parse_env {
444447 let expand_env_vars = |input : & str | -> Value {
445- ENV_VAR_REGEX . replace_all ( input, |caps : & regex:: Captures < ' _ > | {
446- let var_name = & caps[ 1 ] ;
447- env:: var ( var_name) . unwrap_or_else ( |_| format ! ( "${}" , var_name) )
448- } ) . into ( )
448+ ENV_VAR_REGEX
449+ . replace_all ( input, |caps : & regex:: Captures < ' _ > | {
450+ let var_name = & caps[ 1 ] ;
451+ env:: var ( var_name) . unwrap_or_else ( |_| format ! ( "${}" , var_name) )
452+ } )
453+ . into ( )
449454 } ;
450455
451456 for val in static_fields. values_mut ( ) {
0 commit comments