std: Make console log off/on controls work with newsched
This commit is contained in:
parent
1b7c99655f
commit
95eb01957b
5 changed files with 55 additions and 16 deletions
|
|
@ -11,13 +11,20 @@
|
|||
//! Logging
|
||||
|
||||
use option::*;
|
||||
use os;
|
||||
use either::*;
|
||||
use rt;
|
||||
use rt::OldTaskContext;
|
||||
use rt::logging::{Logger, StdErrLogger};
|
||||
|
||||
/// Turns on logging to stdout globally
|
||||
pub fn console_on() {
|
||||
unsafe {
|
||||
rustrt::rust_log_console_on();
|
||||
if rt::context() == OldTaskContext {
|
||||
unsafe {
|
||||
rustrt::rust_log_console_on();
|
||||
}
|
||||
} else {
|
||||
rt::logging::console_on();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,8 +36,17 @@ pub fn console_on() {
|
|||
* the RUST_LOG environment variable
|
||||
*/
|
||||
pub fn console_off() {
|
||||
unsafe {
|
||||
rustrt::rust_log_console_off();
|
||||
// If RUST_LOG is set then the console can't be turned off
|
||||
if os::getenv("RUST_LOG").is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
if rt::context() == OldTaskContext {
|
||||
unsafe {
|
||||
rustrt::rust_log_console_off();
|
||||
}
|
||||
} else {
|
||||
rt::logging::console_off();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use either::*;
|
||||
use libc;
|
||||
|
||||
pub trait Logger {
|
||||
fn log(&mut self, msg: Either<~str, &'static str>);
|
||||
|
|
@ -20,6 +21,10 @@ impl Logger for StdErrLogger {
|
|||
fn log(&mut self, msg: Either<~str, &'static str>) {
|
||||
use io::{Writer, WriterUtil};
|
||||
|
||||
if !should_log_console() {
|
||||
return;
|
||||
}
|
||||
|
||||
let s: &str = match msg {
|
||||
Left(ref s) => {
|
||||
let s: &str = *s;
|
||||
|
|
@ -44,7 +49,6 @@ pub fn init(crate_map: *u8) {
|
|||
use str;
|
||||
use ptr;
|
||||
use option::{Some, None};
|
||||
use libc::c_char;
|
||||
|
||||
let log_spec = os::getenv("RUST_LOG");
|
||||
match log_spec {
|
||||
|
|
@ -61,8 +65,16 @@ pub fn init(crate_map: *u8) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern {
|
||||
fn rust_update_log_settings(crate_map: *u8, settings: *c_char);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn console_on() { unsafe { rust_log_console_on() } }
|
||||
pub fn console_off() { unsafe { rust_log_console_off() } }
|
||||
fn should_log_console() -> bool { unsafe { rust_should_log_console() != 0 } }
|
||||
|
||||
extern {
|
||||
fn rust_update_log_settings(crate_map: *u8, settings: *libc::c_char);
|
||||
fn rust_log_console_on();
|
||||
fn rust_log_console_off();
|
||||
fn rust_should_log_console() -> libc::uintptr_t;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue