Skip to main content

Module log

Module log 

Source
Expand description

SDK diagnostics logging.

Logging is disabled by default (TDLogLevel::Off). Raise the level with set_log_level, or route diagnostics into your own logging stack by installing a TDLogger implementation with set_custom_logger:

use std::sync::{Arc, Mutex};
use thinkingdata_core::log::{set_custom_logger, set_log_level, TDLogger, TDLogLevel};

struct Collect(Mutex<Vec<String>>);
impl TDLogger for Collect {
    fn print(&self, message: &str) {
        self.0.lock().unwrap().push(message.to_string());
    }
}

set_custom_logger(Arc::new(Collect(Mutex::new(Vec::new()))));
set_log_level(TDLogLevel::Info);
assert_eq!(thinkingdata_core::log::get_log_level(), TDLogLevel::Info);
set_log_level(TDLogLevel::Off);

Enums§

TDLogLevel
The log output level, ordered from quietest to most verbose.

Constants§

SDK_LOG_PREFIX
Prefix prepended to every diagnostic message.

Traits§

TDLogger
A destination for SDK diagnostic messages.

Functions§

clear_custom_logger
Remove a previously installed custom logger.
get_log_level
Get the current log output level.
set_custom_logger
Install a custom logger that receives every formatted diagnostic message.
set_log_level
Set the log output level.