about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorPhilipp Brüschweiler <blei42@gmail.com>2013-12-02 21:47:57 +0100
committerPhilipp Brüschweiler <blei42@gmail.com>2013-12-02 21:47:57 +0100
commita75f72d45a1c1399adab0e123acdb76582a360ae (patch)
tree5f99ea6941e8bebb6b7950f4b0adec6edc392faf /src/libstd
parent61443dc1f5089df637edba83587b9f3020063266 (diff)
downloadrust-a75f72d45a1c1399adab0e123acdb76582a360ae.tar.gz
rust-a75f72d45a1c1399adab0e123acdb76582a360ae.zip
Add a macro to check if logging at a given label is enabled
This is useful when the information that is needed to do useful logging
is expensive to produce.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/logging.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/libstd/logging.rs b/src/libstd/logging.rs
index 1b540823f17..1605dcebf1a 100644
--- a/src/libstd/logging.rs
+++ b/src/libstd/logging.rs
@@ -20,14 +20,20 @@ There are five macros that the logging subsystem uses:
 
 * `log!(level, ...)` - the generic logging macro, takes a level as a u32 and any
                        related `format!` arguments
-* `debug!(...)` - a macro hard-wired to the log level of 4
-* `info!(...)` - a macro hard-wired to the log level of 3
-* `warn!(...)` - a macro hard-wired to the log level of 2
-* `error!(...)` - a macro hard-wired to the log level of 1
+* `debug!(...)` - a macro hard-wired to the log level of `DEBUG`
+* `info!(...)` - a macro hard-wired to the log level of `INFO`
+* `warn!(...)` - a macro hard-wired to the log level of `WARN`
+* `error!(...)` - a macro hard-wired to the log level of `ERROR`
 
 All of these macros use the same style of syntax as the `format!` syntax
 extension. Details about the syntax can be found in the documentation of
-`std::fmt` along with the Rust tutorial/manual
+`std::fmt` along with the Rust tutorial/manual.
+
+If you want to check at runtime if a given logging level is enabled (e.g. if the
+information you would want to log is expensive to produce), you can use the
+following macro:
+
+* `log_enabled!(level)` - returns true if logging of the given level is enabled
 
 ## Enabling logging
 
@@ -95,6 +101,15 @@ use rt::local::Local;
 use rt::logging::{Logger, StdErrLogger};
 use rt::task::Task;
 
+/// Debug log level
+pub static DEBUG: u32 = 4;
+/// Info log level
+pub static INFO: u32 = 3;
+/// Warn log level
+pub static WARN: u32 = 2;
+/// Error log level
+pub static ERROR: u32 = 1;
+
 /// This function is called directly by the compiler when using the logging
 /// macros. This function does not take into account whether the log level
 /// specified is active or not, it will always log something if this method is