Skip to content

Commit f5f36e8

Browse files
committed
rt: Allow console logging to be turned off
1 parent 7150643 commit f5f36e8

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/rt/rust_builtin.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,21 @@ rust_set_exit_status(intptr_t code) {
567567
task->kernel->set_exit_status((int)code);
568568
}
569569

570+
extern void log_console_on();
571+
572+
extern "C" CDECL void
573+
rust_log_console_on() {
574+
log_console_on();
575+
}
576+
577+
extern void log_console_off(rust_env *env);
578+
579+
extern "C" CDECL void
580+
rust_log_console_off() {
581+
rust_task *task = rust_scheduler::get_task();
582+
log_console_off(task->kernel->env);
583+
}
584+
570585
//
571586
// Local Variables:
572587
// mode: C++

src/rt/rust_log.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@
1313
* Synchronizes access to the underlying logging mechanism.
1414
*/
1515
static lock_and_signal _log_lock;
16+
/**
17+
* Indicates whether we are outputing to the console.
18+
* Protected by _log_lock;
19+
*/
20+
static bool _log_to_console = true;
21+
22+
/*
23+
* Request that console logging be turned on.
24+
*/
25+
void
26+
log_console_on() {
27+
scoped_lock with(_log_lock);
28+
_log_to_console = true;
29+
}
30+
31+
/*
32+
* Request that console logging be turned off. Can be
33+
* overridden by the environment.
34+
*/
35+
void
36+
log_console_off(rust_env *env) {
37+
scoped_lock with(_log_lock);
38+
if (env->logspec == NULL) {
39+
_log_to_console = false;
40+
}
41+
}
1642

1743
rust_log::rust_log(rust_srv *srv, rust_scheduler *sched) :
1844
_srv(srv),
@@ -71,7 +97,9 @@ rust_log::trace_ln(char *prefix, char *message) {
7197
_log_lock.lock();
7298
append_string(buffer, "%s", prefix);
7399
append_string(buffer, "%s", message);
74-
_srv->log(buffer);
100+
if (_log_to_console) {
101+
_srv->log(buffer);
102+
}
75103
_log_lock.unlock();
76104
}
77105

src/rt/rustrt.def.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ rust_get_stdout
3636
rust_get_stderr
3737
rust_str_push
3838
rust_list_files
39+
rust_log_console_on
40+
rust_log_console_off
3941
rust_port_detach
4042
rust_port_size
4143
rust_process_wait

0 commit comments

Comments
 (0)