Skip to content

Commit 95eb019

Browse files
committed
std: Make console log off/on controls work with newsched
1 parent 1b7c996 commit 95eb019

File tree

5 files changed

+54
-15
lines changed

5 files changed

+54
-15
lines changed

src/libstd/logging.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111
//! Logging
1212
1313
use option::*;
14+
use os;
1415
use either::*;
16+
use rt;
17+
use rt::OldTaskContext;
1518
use rt::logging::{Logger, StdErrLogger};
1619

1720
/// Turns on logging to stdout globally
1821
pub fn console_on() {
19-
unsafe {
20-
rustrt::rust_log_console_on();
22+
if rt::context() == OldTaskContext {
23+
unsafe {
24+
rustrt::rust_log_console_on();
25+
}
26+
} else {
27+
rt::logging::console_on();
2128
}
2229
}
2330

@@ -29,8 +36,17 @@ pub fn console_on() {
2936
* the RUST_LOG environment variable
3037
*/
3138
pub fn console_off() {
32-
unsafe {
33-
rustrt::rust_log_console_off();
39+
// If RUST_LOG is set then the console can't be turned off
40+
if os::getenv("RUST_LOG").is_some() {
41+
return;
42+
}
43+
44+
if rt::context() == OldTaskContext {
45+
unsafe {
46+
rustrt::rust_log_console_off();
47+
}
48+
} else {
49+
rt::logging::console_off();
3450
}
3551
}
3652

src/libstd/rt/logging.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use either::*;
12+
use libc;
1213

1314
pub trait Logger {
1415
fn log(&mut self, msg: Either<~str, &'static str>);
@@ -20,6 +21,10 @@ impl Logger for StdErrLogger {
2021
fn log(&mut self, msg: Either<~str, &'static str>) {
2122
use io::{Writer, WriterUtil};
2223

24+
if !should_log_console() {
25+
return;
26+
}
27+
2328
let s: &str = match msg {
2429
Left(ref s) => {
2530
let s: &str = *s;
@@ -44,7 +49,6 @@ pub fn init(crate_map: *u8) {
4449
use str;
4550
use ptr;
4651
use option::{Some, None};
47-
use libc::c_char;
4852

4953
let log_spec = os::getenv("RUST_LOG");
5054
match log_spec {
@@ -61,8 +65,16 @@ pub fn init(crate_map: *u8) {
6165
}
6266
}
6367
}
68+
}
6469

65-
extern {
66-
fn rust_update_log_settings(crate_map: *u8, settings: *c_char);
67-
}
70+
pub fn console_on() { unsafe { rust_log_console_on() } }
71+
pub fn console_off() { unsafe { rust_log_console_off() } }
72+
fn should_log_console() -> bool { unsafe { rust_should_log_console() != 0 } }
73+
74+
extern {
75+
fn rust_update_log_settings(crate_map: *u8, settings: *libc::c_char);
76+
fn rust_log_console_on();
77+
fn rust_log_console_off();
78+
fn rust_should_log_console() -> libc::uintptr_t;
6879
}
80+

src/rt/rust_builtin.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,12 +591,18 @@ rust_log_console_on() {
591591
log_console_on();
592592
}
593593

594-
extern void log_console_off(rust_env *env);
594+
extern void log_console_off();
595595

596596
extern "C" CDECL void
597597
rust_log_console_off() {
598-
rust_task *task = rust_get_current_task();
599-
log_console_off(task->kernel->env);
598+
log_console_off();
599+
}
600+
601+
extern bool should_log_console();
602+
603+
extern "C" CDECL uintptr_t
604+
rust_should_log_console() {
605+
return (uintptr_t)should_log_console();
600606
}
601607

602608
extern "C" CDECL void

src/rt/rust_log.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ log_console_on() {
4343
* overridden by the environment.
4444
*/
4545
void
46-
log_console_off(rust_env *env) {
46+
log_console_off() {
4747
scoped_lock with(_log_lock);
48-
if (env->logspec == NULL) {
49-
_log_to_console = false;
50-
}
48+
_log_to_console = false;
49+
}
50+
51+
bool
52+
should_log_console() {
53+
scoped_lock with(_log_lock);
54+
return _log_to_console;
5155
}
5256

5357
rust_log::rust_log(rust_sched_loop *sched_loop) :

src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ rust_list_dir_wfd_size
3737
rust_list_dir_wfd_fp_buf
3838
rust_log_console_on
3939
rust_log_console_off
40+
rust_should_log_console
4041
rust_set_environ
4142
rust_unset_sigprocmask
4243
rust_sched_current_nonlazy_threads

0 commit comments

Comments
 (0)