diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-01-13 13:19:26 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-01-13 13:44:09 -0800 |
| commit | f5f36e8b49336c1105daee9fb45de12ae039f38e (patch) | |
| tree | 45b3c36841a28ca885964689553f3f8911074675 /src/rt | |
| parent | 7150643588dac57db2292d98fc03ab11b2675758 (diff) | |
| download | rust-f5f36e8b49336c1105daee9fb45de12ae039f38e.tar.gz rust-f5f36e8b49336c1105daee9fb45de12ae039f38e.zip | |
rt: Allow console logging to be turned off
Diffstat (limited to 'src/rt')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 15 | ||||
| -rw-r--r-- | src/rt/rust_log.cpp | 30 | ||||
| -rw-r--r-- | src/rt/rustrt.def.in | 2 |
3 files changed, 46 insertions, 1 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 7bd1c76c187..4bf51da214b 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -567,6 +567,21 @@ rust_set_exit_status(intptr_t code) { task->kernel->set_exit_status((int)code); } +extern void log_console_on(); + +extern "C" CDECL void +rust_log_console_on() { + log_console_on(); +} + +extern void log_console_off(rust_env *env); + +extern "C" CDECL void +rust_log_console_off() { + rust_task *task = rust_scheduler::get_task(); + log_console_off(task->kernel->env); +} + // // Local Variables: // mode: C++ diff --git a/src/rt/rust_log.cpp b/src/rt/rust_log.cpp index d88187e1d32..7119a64d2b8 100644 --- a/src/rt/rust_log.cpp +++ b/src/rt/rust_log.cpp @@ -13,6 +13,32 @@ * Synchronizes access to the underlying logging mechanism. */ static lock_and_signal _log_lock; +/** + * Indicates whether we are outputing to the console. + * Protected by _log_lock; + */ +static bool _log_to_console = true; + +/* + * Request that console logging be turned on. + */ +void +log_console_on() { + scoped_lock with(_log_lock); + _log_to_console = true; +} + +/* + * Request that console logging be turned off. Can be + * overridden by the environment. + */ +void +log_console_off(rust_env *env) { + scoped_lock with(_log_lock); + if (env->logspec == NULL) { + _log_to_console = false; + } +} rust_log::rust_log(rust_srv *srv, rust_scheduler *sched) : _srv(srv), @@ -71,7 +97,9 @@ rust_log::trace_ln(char *prefix, char *message) { _log_lock.lock(); append_string(buffer, "%s", prefix); append_string(buffer, "%s", message); - _srv->log(buffer); + if (_log_to_console) { + _srv->log(buffer); + } _log_lock.unlock(); } diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index e058ad739df..745e4c6e34b 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -36,6 +36,8 @@ rust_get_stdout rust_get_stderr rust_str_push rust_list_files +rust_log_console_on +rust_log_console_off rust_port_detach rust_port_size rust_process_wait |
