mirror of
				https://github.com/tokio-rs/tracing.git
				synced 2025-11-04 07:23:02 +00:00 
			
		
		
		
	subscriber: correct fmt::init() documentation (#2224)
## Motivation Previously the documentation for `fmt::init()` was misleading. It stated that it was shorthand for `fmt().init()`. This lead to confusion as users would expect the same behavior from both. However `fmt::init()` would, whether you used the env-filter feature or not, rely on RUST_LOG to set the tracing level. `fmt().init()` does not do this and it must be set with a specific configuration via `with_env_filter`. ## Solution The documentation has been updated to no longer state that it is 1:1 shorthand for the other. The documentation now specifically points out that you must be using the `env-filter` feature and gives a correct example to mimic the `fmt::init()` behavior using `fmt().init()`. Fixes #2217 Fixes #1329 Co-authored-by: Eliza Weisman <eliza@buoyant.io>
This commit is contained in:
		
							parent
							
								
									a3868af664
								
							
						
					
					
						commit
						b6762daf52
					
				@ -1203,13 +1203,19 @@ pub fn try_init() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
 | 
			
		||||
/// Install a global tracing subscriber that listens for events and
 | 
			
		||||
/// filters based on the value of the [`RUST_LOG` environment variable].
 | 
			
		||||
///
 | 
			
		||||
/// The configuration of the subscriber initialized by this function
 | 
			
		||||
/// depends on what [feature flags](crate#feature-flags) are enabled.
 | 
			
		||||
///
 | 
			
		||||
/// If the `tracing-log` feature is enabled, this will also install
 | 
			
		||||
/// the LogTracer to convert `Log` records into `tracing` `Event`s.
 | 
			
		||||
///
 | 
			
		||||
/// This is shorthand for
 | 
			
		||||
/// If the `env-filter` feature is enabled, this is shorthand for
 | 
			
		||||
///
 | 
			
		||||
/// ```rust
 | 
			
		||||
/// tracing_subscriber::fmt().init()
 | 
			
		||||
/// # use tracing_subscriber::EnvFilter;
 | 
			
		||||
/// tracing_subscriber::fmt()
 | 
			
		||||
///     .with_env_filter(EnvFilter::from_default_env())
 | 
			
		||||
///     .init();
 | 
			
		||||
/// ```
 | 
			
		||||
///
 | 
			
		||||
/// # Panics
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user