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(plugin, 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=6u);
35 ($lvl:expr, $($arg:tt)+) => ({
36 static LOC: ::log::LogLocation = ::log::LogLocation {
39 module_path: module_path!(),
42 if log_enabled!(lvl) {
43 format_args!(|args| { ::log::log(lvl, &LOC, args) }, $($arg)+)
48 /// A convenience macro for logging at the error log level.
53 /// #![feature(phase)]
54 /// #[phase(plugin, link)] extern crate log;
58 /// error!("the build has failed with error code: {}", error);
63 ($($arg:tt)*) => (log!(::log::ERROR, $($arg)*))
66 /// A convenience macro for logging at the warning log level.
71 /// #![feature(phase)]
72 /// #[phase(plugin, link)] extern crate log;
76 /// warn!("you may like to know that a process exited with: {}", code);
81 ($($arg:tt)*) => (log!(::log::WARN, $($arg)*))
84 /// A convenience macro for logging at the info log level.
89 /// #![feature(phase)]
90 /// #[phase(plugin, link)] extern crate log;
94 /// info!("this function is about to return: {}", ret);
99 ($($arg:tt)*) => (log!(::log::INFO, $($arg)*))
102 /// A convenience macro for logging at the debug log level. This macro can also
103 /// be omitted at compile time by passing `--cfg ndebug` to the compiler. If
104 /// this option is not passed, then debug statements will be compiled.
109 /// #![feature(phase)]
110 /// #[phase(plugin, link)] extern crate log;
113 /// debug!("x = {x}, y = {y}", x=10i, y=20i);
118 ($($arg:tt)*) => (if cfg!(not(ndebug)) { log!(::log::DEBUG, $($arg)*) })
121 /// A macro to test whether a log level is enabled for the current module.
126 /// #![feature(phase)]
127 /// #[phase(plugin, link)] extern crate log;
130 /// # struct Point { x: int, y: int }
131 /// # fn some_expensive_computation() -> Point { Point { x: 1, y: 2 } }
132 /// if log_enabled!(log::DEBUG) {
133 /// let x = some_expensive_computation();
134 /// debug!("x.x = {}, x.y = {}", x.x, x.y);
139 macro_rules! log_enabled(
142 (lvl != ::log::DEBUG || cfg!(not(ndebug))) &&
143 lvl <= ::log::log_level() &&
144 ::log::mod_enabled(lvl, module_path!())