2012-07-04 16:53:12 -05:00
|
|
|
//! Logging
|
2012-01-13 15:20:11 -06:00
|
|
|
|
2012-09-20 19:18:18 -05:00
|
|
|
// NB: transitionary, de-mode-ing.
|
|
|
|
#[forbid(deprecated_mode)];
|
|
|
|
#[forbid(deprecated_pattern)];
|
|
|
|
|
2012-09-25 14:17:20 -05:00
|
|
|
use cast::transmute;
|
|
|
|
|
2012-01-13 15:20:11 -06:00
|
|
|
#[nolink]
|
2012-07-03 18:11:00 -05:00
|
|
|
extern mod rustrt {
|
2012-01-13 15:20:11 -06:00
|
|
|
fn rust_log_console_on();
|
|
|
|
fn rust_log_console_off();
|
2012-09-25 14:17:20 -05:00
|
|
|
fn rust_log_str(level: u32, string: *libc::c_char, size: libc::size_t);
|
2012-01-13 15:20:11 -06:00
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Turns on logging to stdout globally
|
2012-09-26 18:26:19 -05:00
|
|
|
pub fn console_on() {
|
2012-01-13 15:20:11 -06:00
|
|
|
rustrt::rust_log_console_on();
|
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* Turns off logging to stdout globally
|
|
|
|
*
|
|
|
|
* Turns off the console unless the user has overridden the
|
|
|
|
* runtime environment's logging spec, e.g. by setting
|
|
|
|
* the RUST_LOG environment variable
|
|
|
|
*/
|
2012-09-26 18:26:19 -05:00
|
|
|
pub fn console_off() {
|
2012-01-13 15:20:11 -06:00
|
|
|
rustrt::rust_log_console_off();
|
2012-09-25 14:17:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(notest)]
|
|
|
|
#[lang="log_type"]
|
|
|
|
pub fn log_type<T>(level: u32, object: &T) {
|
|
|
|
let bytes = do io::with_bytes_writer() |writer| {
|
|
|
|
repr::write_repr(writer, object);
|
|
|
|
};
|
|
|
|
unsafe {
|
|
|
|
let len = bytes.len() as libc::size_t;
|
|
|
|
rustrt::rust_log_str(level, transmute(vec::raw::to_ptr(bytes)), len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|