1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
15 /// The standard logging macro
17 /// This macro will generically log over a provided level (of type u32) with a
18 /// format!-based argument list. See documentation in `std::fmt` for details on
19 /// how to use the syntax.
24 /// #[feature(phase)];
25 /// #[phase(syntax, link)] extern crate log;
28 /// log!(log::DEBUG, "this is a debug message");
29 /// log!(log::WARN, "this is a warning {}", "message");
30 /// log!(6, "this is a custom logging level: {level}", level=6);
35 ($lvl:expr, $($arg:tt)+) => ({
37 if log_enabled!(lvl) {
38 format_args!(|args| { ::log::log(lvl, args) }, $($arg)+)
43 /// A convenience macro for logging at the error log level.
48 /// #[feature(phase)];
49 /// #[phase(syntax, link)] extern crate log;
53 /// error!("the build has failed with error code: {}", error);
58 ($($arg:tt)*) => (log!(::log::ERROR, $($arg)*))
61 /// A convenience macro for logging at the warning log level.
66 /// #[feature(phase)];
67 /// #[phase(syntax, link)] extern crate log;
71 /// warn!("you may like to know that a process exited with: {}", code);
76 ($($arg:tt)*) => (log!(::log::WARN, $($arg)*))
79 /// A convenience macro for logging at the info log level.
84 /// #[feature(phase)];
85 /// #[phase(syntax, link)] extern crate log;
89 /// info!("this function is about to return: {}", ret);
94 ($($arg:tt)*) => (log!(::log::INFO, $($arg)*))
97 /// A convenience macro for logging at the debug log level. This macro can also
98 /// be omitted at compile time by passing `--cfg ndebug` to the compiler. If
99 /// this option is not passed, then debug statements will be compiled.
104 /// #[feature(phase)];
105 /// #[phase(syntax, link)] extern crate log;
108 /// debug!("x = {x}, y = {y}", x=10, y=20);
113 ($($arg:tt)*) => (if cfg!(not(ndebug)) { log!(::log::DEBUG, $($arg)*) })
116 /// A macro to test whether a log level is enabled for the current module.
121 /// #[feature(phase)];
122 /// #[phase(syntax, link)] extern crate log;
125 /// # struct Point { x: int, y: int }
126 /// # fn some_expensive_computation() -> Point { Point { x: 1, y: 2 } }
127 /// if log_enabled!(log::DEBUG) {
128 /// let x = some_expensive_computation();
129 /// debug!("x.x = {}, x.y = {}", x.x, x.y);
134 macro_rules! log_enabled(
137 (lvl != ::log::DEBUG || cfg!(not(ndebug))) &&
138 lvl <= ::log::log_level() &&
139 ::log::mod_enabled(lvl, module_path!())