fn write_log(&self, msg: String, msg_level: Level) {
        if STATE.load(Ordering::Relaxed) == INITIALIZED {
            if let Some(guard) = buf_guard(&self.log_buf).as_mut() {
                // No need to explicitly call flush because the underlying LineWriter flushes
                // automatically whenever a newline is detected (and we always end with a
                // newline the current write).
                if guard.write_all(format!("{}\n", msg).as_bytes()).is_err() {
                    // No reason to log the error to stderr here, just increment the metric.
                }
            } else {
                panic!("Failed to write to the provided log destination due to poisoned lock");
            }
        } else if msg_level <= Level::Warn {
            eprintln!("{}", msg);
        } else {
            println!("{}", msg);
        }
    }
// In a future PR we'll update the way things are written to the selected destination to avoid
// the creation and allocation of unnecessary intermediate Strings. The `write_log` method takes
// care of the common logic involved in writing regular log messages.
In a future PR we'll update the way things are written to the selected destination to avoid
the creation and allocation of unnecessary intermediate Strings. The `write_log` method takes
care of the common logic involved in writing regular log messages.
In a future PR we ' ll update the way things are written to the selected destination to avoid the creation and allocation of unnecessary intermediate Strings . The ` write_log ` method takes care of the common logic involved in writing regular log messages .
fn write_log(&self, msg: String, msg_level: Level) {
        if STATE.load(Ordering::Relaxed) == INITIALIZED {
            if let Some(guard) = buf_guard(&self.log_buf).as_mut() {
                // No need to explicitly call flush because the underlying LineWriter flushes
                // automatically whenever a newline is detected (and we always end with a
                // newline the current write).
                if guard.write_all(format!("{}\n", msg).as_bytes()).is_err() {
                    // No reason to log the error to stderr here, just increment the metric.
                }
            } else {
                panic!("Failed to write to the provided log destination due to poisoned lock");
            }
        } else if msg_level <= Level::Warn {
            eprintln!("{}", msg);
        } else {
            println!("{}", msg);
        }
    }
fn write_log ( & self , msg : String , msg_level : Level ) { if STATE . load ( Ordering :: Relaxed ) == INITIALIZED { if let Some ( guard ) = buf_guard ( & self . log_buf ) . as_mut ( ) { // No need to explicitly call flush because the underlying LineWriter flushes // automatically whenever a newline is detected (and we always end with a // newline the current write). if guard . write_all ( format ! ( " \n " msg ) . as_bytes ( ) ) . is_err ( ) { // No reason to log the error to stderr here, just increment the metric. } } else { panic ! ( " " ) ; } } else if msg_level <= Level :: Warn { eprintln ! ( " " msg ) ; } else { println ! ( " " msg ) ; } }
In a future PR we'll update the way things are written to the selected destination to avoid
the creation and allocation of unnecessary intermediate Strings.
In a future PR we ' ll update the way things are written to the selected destination to avoid the creation and allocation of unnecessary intermediate Strings .
&self
msg
String
msg_level
Level