Skip to content

Commit 4ef8645

Browse files
committed
---
yaml --- r: 142636 b: refs/heads/try2 c: 95eb019 h: refs/heads/master v: v3
1 parent 20bfd1e commit 4ef8645

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 1b7c99655f300aa0b8ba216cd2029dc588c3ef88
8+
refs/heads/try2: 95eb01957bf23922abdf083f677c6c2d6927713a
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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

branches/try2/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+

branches/try2/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

branches/try2/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) :

branches/try2/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)