2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
//! Logging
|
2012-01-13 15:20:11 -06:00
|
|
|
|
2013-04-27 20:57:15 -05:00
|
|
|
use option::*;
|
2013-06-21 18:52:07 -05:00
|
|
|
use os;
|
|
|
|
use rt;
|
2013-09-14 12:37:45 -05:00
|
|
|
use rt::logging::{Logger, StdErrLogger};
|
|
|
|
use send_str::SendStrOwned;
|
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() {
|
2013-08-01 01:12:20 -05:00
|
|
|
rt::logging::console_on();
|
2012-01-13 15:20:11 -06:00
|
|
|
}
|
|
|
|
|
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() {
|
2013-06-21 18:52:07 -05:00
|
|
|
// If RUST_LOG is set then the console can't be turned off
|
|
|
|
if os::getenv("RUST_LOG").is_some() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-01 01:12:20 -05:00
|
|
|
rt::logging::console_off();
|
2012-09-25 14:17:20 -05:00
|
|
|
}
|
|
|
|
|
2013-04-27 20:57:15 -05:00
|
|
|
fn newsched_log_str(msg: ~str) {
|
2013-05-19 18:50:21 -05:00
|
|
|
use rt::task::Task;
|
|
|
|
use rt::local::Local;
|
|
|
|
|
2012-09-25 14:17:20 -05:00
|
|
|
unsafe {
|
2013-08-08 13:38:10 -05:00
|
|
|
let optional_task: Option<*mut Task> = Local::try_unsafe_borrow();
|
|
|
|
match optional_task {
|
2013-04-27 20:57:15 -05:00
|
|
|
Some(local) => {
|
|
|
|
// Use the available logger
|
2013-09-14 12:37:45 -05:00
|
|
|
(*local).logger.log(SendStrOwned(msg));
|
2013-04-27 20:57:15 -05:00
|
|
|
}
|
|
|
|
None => {
|
|
|
|
// There is no logger anywhere, just write to stderr
|
|
|
|
let mut logger = StdErrLogger;
|
2013-09-14 12:37:45 -05:00
|
|
|
logger.log(SendStrOwned(msg));
|
2013-04-27 20:57:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 01:12:05 -05:00
|
|
|
|
|
|
|
// XXX: This will change soon to not require an allocation. This is an unstable
|
|
|
|
// api which should not be used outside of the macros in ext/expand.
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub fn log(_level: u32, msg: ~str) {
|
|
|
|
newsched_log_str(msg);
|
|
|
|
}
|