File tree Expand file tree Collapse file tree 6 files changed +55
-16
lines changed Expand file tree Collapse file tree 6 files changed +55
-16
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5
5
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
- refs/heads/try2: 1b7c99655f300aa0b8ba216cd2029dc588c3ef88
8
+ refs/heads/try2: 95eb01957bf23922abdf083f677c6c2d6927713a
9
9
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change 11
11
//! Logging
12
12
13
13
use option:: * ;
14
+ use os;
14
15
use either:: * ;
16
+ use rt;
17
+ use rt:: OldTaskContext ;
15
18
use rt:: logging:: { Logger , StdErrLogger } ;
16
19
17
20
/// Turns on logging to stdout globally
18
21
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 ( ) ;
21
28
}
22
29
}
23
30
@@ -29,8 +36,17 @@ pub fn console_on() {
29
36
* the RUST_LOG environment variable
30
37
*/
31
38
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 ( ) ;
34
50
}
35
51
}
36
52
Original file line number Diff line number Diff line change 9
9
// except according to those terms.
10
10
11
11
use either:: * ;
12
+ use libc;
12
13
13
14
pub trait Logger {
14
15
fn log ( & mut self , msg : Either < ~str , & ' static str > ) ;
@@ -20,6 +21,10 @@ impl Logger for StdErrLogger {
20
21
fn log ( & mut self , msg : Either < ~str , & ' static str > ) {
21
22
use io:: { Writer , WriterUtil } ;
22
23
24
+ if !should_log_console ( ) {
25
+ return ;
26
+ }
27
+
23
28
let s: & str = match msg {
24
29
Left ( ref s) => {
25
30
let s: & str = * s;
@@ -44,7 +49,6 @@ pub fn init(crate_map: *u8) {
44
49
use str;
45
50
use ptr;
46
51
use option:: { Some , None } ;
47
- use libc:: c_char;
48
52
49
53
let log_spec = os:: getenv ( "RUST_LOG" ) ;
50
54
match log_spec {
@@ -61,8 +65,16 @@ pub fn init(crate_map: *u8) {
61
65
}
62
66
}
63
67
}
68
+ }
64
69
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 ;
68
79
}
80
+
Original file line number Diff line number Diff line change @@ -591,12 +591,18 @@ rust_log_console_on() {
591
591
log_console_on ();
592
592
}
593
593
594
- extern void log_console_off (rust_env *env );
594
+ extern void log_console_off ();
595
595
596
596
extern " C" CDECL void
597
597
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 ();
600
606
}
601
607
602
608
extern " C" CDECL void
Original file line number Diff line number Diff line change @@ -43,11 +43,15 @@ log_console_on() {
43
43
* overridden by the environment.
44
44
*/
45
45
void
46
- log_console_off (rust_env *env ) {
46
+ log_console_off () {
47
47
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;
51
55
}
52
56
53
57
rust_log::rust_log (rust_sched_loop *sched_loop) :
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ rust_list_dir_wfd_size
37
37
rust_list_dir_wfd_fp_buf
38
38
rust_log_console_on
39
39
rust_log_console_off
40
+ rust_should_log_console
40
41
rust_set_environ
41
42
rust_unset_sigprocmask
42
43
rust_sched_current_nonlazy_threads
You can’t perform that action at this time.
0 commit comments