From f5f36e8b49336c1105daee9fb45de12ae039f38e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 13 Jan 2012 13:19:26 -0800 Subject: rt: Allow console logging to be turned off --- src/rt/rust_log.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/rt/rust_log.cpp') 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(); } -- cgit 1.4.1-3-g733a5