Skip to content

Commit 695e9fd

Browse files
committed
auto merge of #5293 : brson/rust/logging, r=brson
r? @graydon This removes `log` from the language. Because we can't quite implement it as a syntax extension (probably need globals at the least) it simply renames the keyword to `__log` and hides it behind macros. After this the only way to log is with `debug!`, `info!`, etc. I figure that if there is demand for `log!` we can add it back later. I am not sure that we ever agreed on this course of action, though I *think* there is consensus that `log` shouldn't be a statement.
2 parents 0ad3a11 + 9c7e16e commit 695e9fd

File tree

228 files changed

+892
-995
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+892
-995
lines changed

doc/rust.md

+10-63
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ do drop
212212
else enum extern
213213
false fn for
214214
if impl
215-
let log loop
215+
let loop
216216
match mod mut
217217
priv pub pure
218218
ref return
@@ -805,21 +805,20 @@ Use declarations support a number of "convenience" notations:
805805
An example of `use` declarations:
806806

807807
~~~~
808-
use foo = core::info;
809808
use core::float::sin;
810809
use core::str::{slice, to_upper};
811810
use core::option::Some;
812811
813812
fn main() {
814-
// Equivalent to 'log(core::info, core::float::sin(1.0));'
815-
log(foo, sin(1.0));
813+
// Equivalent to 'info!(core::float::sin(1.0));'
814+
info!(sin(1.0));
816815
817-
// Equivalent to 'log(core::info, core::option::Some(1.0));'
818-
log(info, Some(1.0));
816+
// Equivalent to 'info!(core::option::Some(1.0));'
817+
info!(Some(1.0));
819818
820-
// Equivalent to 'log(core::info,
821-
// core::str::to_upper(core::str::slice("foo", 0, 1)));'
822-
log(info, to_upper(slice("foo", 0, 1)));
819+
// Equivalent to
820+
// 'info!(core::str::to_upper(core::str::slice("foo", 0, 1)));'
821+
info!(to_upper(slice("foo", 0, 1)));
823822
}
824823
~~~~
825824

@@ -990,7 +989,7 @@ output slot type would normally be. For example:
990989

991990
~~~~
992991
fn my_err(s: &str) -> ! {
993-
log(info, s);
992+
info!(s);
994993
fail!();
995994
}
996995
~~~~
@@ -2397,58 +2396,6 @@ fn max(a: int, b: int) -> int {
23972396
}
23982397
~~~~
23992398

2400-
### Log expressions
2401-
2402-
~~~~~~~~{.ebnf .gram}
2403-
log_expr : "log" '(' level ',' expr ')' ;
2404-
~~~~~~~~
2405-
2406-
Evaluating a `log` expression may, depending on runtime configuration, cause a
2407-
value to be appended to an internal diagnostic logging buffer provided by the
2408-
runtime or emitted to a system console. Log expressions are enabled or
2409-
disabled dynamically at run-time on a per-task and per-item basis. See
2410-
[logging system](#logging-system).
2411-
2412-
Each `log` expression must be provided with a *level* argument in
2413-
addition to the value to log. The logging level is a `u32` value, where
2414-
lower levels indicate more-urgent levels of logging. By default, the lowest
2415-
four logging levels (`1_u32 ... 4_u32`) are predefined as the constants
2416-
`error`, `warn`, `info` and `debug` in the `core` library.
2417-
2418-
Additionally, the macros `error!`, `warn!`, `info!` and `debug!` are defined
2419-
in the default syntax-extension namespace. These expand into calls to the
2420-
logging facility composed with calls to the `fmt!` string formatting
2421-
syntax-extension.
2422-
2423-
The following examples all produce the same output, logged at the `error`
2424-
logging level:
2425-
2426-
~~~~
2427-
# let filename = "bulbasaur";
2428-
2429-
// Full version, logging a value.
2430-
log(core::error, ~"file not found: " + filename);
2431-
2432-
// Log-level abbreviated, since core::* is used by default.
2433-
log(error, ~"file not found: " + filename);
2434-
2435-
// Formatting the message using a format-string and fmt!
2436-
log(error, fmt!("file not found: %s", filename));
2437-
2438-
// Using the error! macro, that expands to the previous call.
2439-
error!("file not found: %s", filename);
2440-
~~~~
2441-
2442-
A `log` expression is *not evaluated* when logging at the specified logging-level, module or task is disabled at runtime.
2443-
This makes inactive `log` expressions very cheap;
2444-
they should be used extensively in Rust code, as diagnostic aids,
2445-
as they add little overhead beyond a single integer-compare and branch at runtime.
2446-
2447-
Logging is presently implemented as a language built-in feature,
2448-
as it makes use of compiler-provided, per-module data tables and flags.
2449-
In the future, logging will move into a library, and will no longer be a core expression type.
2450-
It is therefore recommended to use the macro forms of logging (`error!`, `debug!`, etc.) to minimize disruption in code that uses logging.
2451-
24522399

24532400
# Type system
24542401

@@ -3149,7 +3096,7 @@ communication facilities.
31493096

31503097
The runtime contains a system for directing [logging
31513098
expressions](#log-expressions) to a logging console and/or internal logging
3152-
buffers. Logging expressions can be enabled per module.
3099+
buffers. Logging can be enabled per module.
31533100

31543101
Logging output is enabled by setting the `RUST_LOG` environment
31553102
variable. `RUST_LOG` accepts a logging specification made up of a

doc/tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ unit, `()`, as the empty tuple if you like).
744744
~~~~
745745
let mytup: (int, int, float) = (10, 20, 30.0);
746746
match mytup {
747-
(a, b, c) => log(info, a + b + (c as int))
747+
(a, b, c) => info!(a + b + (c as int))
748748
}
749749
~~~~
750750

@@ -760,7 +760,7 @@ For example:
760760
struct MyTup(int, int, float);
761761
let mytup: MyTup = MyTup(10, 20, 30.0);
762762
match mytup {
763-
MyTup(a, b, c) => log(info, a + b + (c as int))
763+
MyTup(a, b, c) => info!(a + b + (c as int))
764764
}
765765
~~~~
766766

src/compiletest/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ pub fn path_div() -> ~str { ~":" }
4646
pub fn path_div() -> ~str { ~";" }
4747
4848
pub fn logv(config: config, s: ~str) {
49-
log(debug, s);
49+
debug!("%s", s);
5050
if config.verbose { io::println(s); }
5151
}

src/libcore/core.rc

+8-1
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,17 @@ pub use clone::Clone;
216216
* more-verbosity. Error is the bottom level, default logging level is
217217
* warn-and-below.
218218
*/
219-
220219
/// The error log level
220+
#[cfg(stage0)]
221221
pub const error : u32 = 1_u32;
222222
/// The warning log level
223+
#[cfg(stage0)]
223224
pub const warn : u32 = 2_u32;
224225
/// The info log level
226+
#[cfg(stage0)]
225227
pub const info : u32 = 3_u32;
226228
/// The debug log level
229+
#[cfg(stage0)]
227230
pub const debug : u32 = 4_u32;
228231

229232

@@ -251,9 +254,13 @@ pub mod rt;
251254
// can be resolved within libcore.
252255
#[doc(hidden)] // FIXME #3538
253256
pub mod core {
257+
#[cfg(stage0)]
254258
pub const error : u32 = 1_u32;
259+
#[cfg(stage0)]
255260
pub const warn : u32 = 2_u32;
261+
#[cfg(stage0)]
256262
pub const info : u32 = 3_u32;
263+
#[cfg(stage0)]
257264
pub const debug : u32 = 4_u32;
258265

259266
pub use cmp;

src/libcore/io.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ impl Writer for *libc::FILE {
683683
*self);
684684
if nout != len as size_t {
685685
error!("error writing buffer");
686-
log(error, os::last_os_error());
686+
error!("%s", os::last_os_error());
687687
fail!();
688688
}
689689
}
@@ -733,7 +733,7 @@ impl Writer for fd_t {
733733
let nout = libc::write(*self, vb, len as size_t);
734734
if nout < 0 as ssize_t {
735735
error!("error writing buffer");
736-
log(error, os::last_os_error());
736+
error!("%s", os::last_os_error());
737737
fail!();
738738
}
739739
count += nout as uint;
@@ -1288,7 +1288,6 @@ pub mod fsync {
12881288

12891289
#[cfg(test)]
12901290
mod tests {
1291-
use debug;
12921291
use i32;
12931292
use io::{BytesWriter, SeekCur, SeekEnd, SeekSet};
12941293
use io;
@@ -1301,10 +1300,10 @@ mod tests {
13011300
#[test]
13021301
fn test_simple() {
13031302
let tmpfile = &Path("tmp/lib-io-test-simple.tmp");
1304-
log(debug, tmpfile);
1303+
debug!(tmpfile);
13051304
let frood: ~str =
13061305
~"A hoopy frood who really knows where his towel is.";
1307-
log(debug, copy frood);
1306+
debug!(copy frood);
13081307
{
13091308
let out: io::Writer =
13101309
result::get(
@@ -1313,7 +1312,7 @@ mod tests {
13131312
}
13141313
let inp: io::Reader = result::get(&io::file_reader(tmpfile));
13151314
let frood2: ~str = inp.read_c_str();
1316-
log(debug, copy frood2);
1315+
debug!(copy frood2);
13171316
fail_unless!(frood == frood2);
13181317
}
13191318

src/libcore/os.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ pub fn env() -> ~[(~str,~str)] {
208208
let mut result = ~[];
209209
ptr::array_each(environ, |e| {
210210
let env_pair = str::raw::from_c_str(e);
211-
log(debug, fmt!("get_env_pairs: %s",
212-
env_pair));
211+
debug!("get_env_pairs: %s",
212+
env_pair);
213213
result.push(env_pair);
214214
});
215215
result
@@ -219,9 +219,8 @@ pub fn env() -> ~[(~str,~str)] {
219219
let mut pairs = ~[];
220220
for input.each |p| {
221221
let vs = str::splitn_char(*p, '=', 1);
222-
log(debug,
223-
fmt!("splitting: len: %u",
224-
vs.len()));
222+
debug!("splitting: len: %u",
223+
vs.len());
225224
fail_unless!(vs.len() == 2);
226225
pairs.push((copy vs[0], copy vs[1]));
227226
}
@@ -682,10 +681,10 @@ pub fn list_dir(p: &Path) -> ~[~str] {
682681
let input = p.to_str();
683682
let mut strings = ~[];
684683
let input_ptr = ::cast::transmute(&input[0]);
685-
log(debug, "os::list_dir -- BEFORE OPENDIR");
684+
debug!("os::list_dir -- BEFORE OPENDIR");
686685
let dir_ptr = opendir(input_ptr);
687686
if (dir_ptr as uint != 0) {
688-
log(debug, "os::list_dir -- opendir() SUCCESS");
687+
debug!("os::list_dir -- opendir() SUCCESS");
689688
let mut entry_ptr = readdir(dir_ptr);
690689
while (entry_ptr as uint != 0) {
691690
strings.push(
@@ -697,11 +696,11 @@ pub fn list_dir(p: &Path) -> ~[~str] {
697696
closedir(dir_ptr);
698697
}
699698
else {
700-
log(debug, "os::list_dir -- opendir() FAILURE");
699+
debug!("os::list_dir -- opendir() FAILURE");
701700
}
702-
log(debug,
703-
fmt!("os::list_dir -- AFTER -- #: %?",
704-
strings.len()));
701+
debug!(
702+
"os::list_dir -- AFTER -- #: %?",
703+
strings.len());
705704
strings
706705
}
707706
#[cfg(windows)]
@@ -1258,7 +1257,6 @@ pub mod consts {
12581257
#[cfg(test)]
12591258
#[allow(non_implicitly_copyable_typarams)]
12601259
mod tests {
1261-
use debug;
12621260
use libc::{c_int, c_void, size_t};
12631261
use libc;
12641262
use option::{None, Option, Some};
@@ -1274,7 +1272,7 @@ mod tests {
12741272
12751273
#[test]
12761274
pub fn last_os_error() {
1277-
log(debug, os::last_os_error());
1275+
debug!(os::last_os_error());
12781276
}
12791277
12801278
#[test]
@@ -1320,7 +1318,7 @@ mod tests {
13201318
while i < 100 { s += ~"aaaaaaaaaa"; i += 1; }
13211319
let n = make_rand_name();
13221320
setenv(n, s);
1323-
log(debug, copy s);
1321+
debug!(copy s);
13241322
fail_unless!(getenv(n) == option::Some(s));
13251323
}
13261324
@@ -1329,7 +1327,7 @@ mod tests {
13291327
let path = os::self_exe_path();
13301328
fail_unless!(path.is_some());
13311329
let path = path.get();
1332-
log(debug, copy path);
1330+
debug!(copy path);
13331331
13341332
// Hard to test this function
13351333
fail_unless!(path.is_absolute);
@@ -1342,7 +1340,7 @@ mod tests {
13421340
fail_unless!(vec::len(e) > 0u);
13431341
for vec::each(e) |p| {
13441342
let (n, v) = copy *p;
1345-
log(debug, copy n);
1343+
debug!(copy n);
13461344
let v2 = getenv(n);
13471345
// MingW seems to set some funky environment variables like
13481346
// "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned
@@ -1367,10 +1365,10 @@ mod tests {
13671365
fn test() {
13681366
fail_unless!((!Path("test-path").is_absolute));
13691367
1370-
log(debug, ~"Current working directory: " + getcwd().to_str());
1368+
debug!(~"Current working directory: " + getcwd().to_str());
13711369
1372-
log(debug, make_absolute(&Path("test-path")));
1373-
log(debug, make_absolute(&Path("/usr/bin")));
1370+
debug!(make_absolute(&Path("test-path")));
1371+
debug!(make_absolute(&Path("/usr/bin")));
13741372
}
13751373
13761374
#[test]
@@ -1433,7 +1431,7 @@ mod tests {
14331431
fail_unless!((vec::len(dirs) > 0u));
14341432
14351433
for vec::each(dirs) |dir| {
1436-
log(debug, copy *dir);
1434+
debug!(copy *dir);
14371435
}
14381436
}
14391437

src/libcore/prelude.rs

-15
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,3 @@ pub use u64;
8282
pub use u8;
8383
pub use uint;
8484
pub use vec;
85-
86-
/*
87-
* Export the log levels as global constants. Higher levels mean
88-
* more-verbosity. Error is the bottom level, default logging level is
89-
* warn-and-below.
90-
*/
91-
92-
/// The error log level
93-
pub const error : u32 = 1_u32;
94-
/// The warning log level
95-
pub const warn : u32 = 2_u32;
96-
/// The info log level
97-
pub const info : u32 = 3_u32;
98-
/// The debug log level
99-
pub const debug : u32 = 4_u32;

0 commit comments

Comments
 (0)