try_init

Function try_init 

Source
pub fn try_init() -> Result<(), SetLoggerError>
Expand description

Attempts to initialize the global logger with an instance of env_logger::Logger with ECS-Logging formatting.

This should be called early in the execution of a Rust program. Any log events that occur before initialization will be ignored.

§Errors

This function returns log::SetLoggerError if it is called more than once, or if another library has already initialized a global logger.

§Example

use log::error;

error!("this is NOT logged");

assert!(ecs_logger::try_init().is_ok());

error!("this is logged");

// try_init should not be called more than once
assert!(ecs_logger::try_init().is_err());