pub fn setup_logger()Expand description
Install the tracing subscriber used by every example and binary
in the crate.
The level is read from the DERIBIT_LOG_LEVEL environment variable
once, on the first call. Recognised values: TRACE, DEBUG,
INFO, WARN, ERROR. Anything else (or an unset variable)
defaults to INFO.
The subscriber is registered as the process-global default via
tracing::subscriber::set_global_default, which tracing allows
only once per process. A Once guard makes subsequent calls to
this function safe: they return immediately without touching the
already-installed subscriber, so applications that wire logging
from multiple entry points (tests, libs, main) do not race.
Changing DERIBIT_LOG_LEVEL after the first call has no effect —
tracing does not support replacing the global default at runtime.
§Example
use deribit_websocket::utils::setup_logger;
// Set log level via environment variable (unsafe in Rust 2024 edition)
unsafe {
std::env::set_var("DERIBIT_LOG_LEVEL", "DEBUG");
}
// Initialize the logger
setup_logger();
// Now you can use tracing macros
tracing::info!("Logger initialized");