Skip to content

Commit bbc42cf

Browse files
committed
---
yaml --- r: 49869 b: refs/heads/auto c: e28d4b3 h: refs/heads/master i: 49867: d20e58c v: v3
1 parent 07a249d commit bbc42cf

File tree

239 files changed

+1215
-1201
lines changed

Some content is hidden

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

239 files changed

+1215
-1201
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 9c7e16e48d15b3380cc680f6194fe3516867d2db
17+
refs/heads/auto: e28d4b3516f0703ddb5407bf8cd7fc7e273743bb
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167

branches/auto/doc/rust.md

Lines changed: 63 additions & 10 deletions
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 loop
215+
let log loop
216216
match mod mut
217217
priv pub pure
218218
ref return
@@ -805,20 +805,21 @@ Use declarations support a number of "convenience" notations:
805805
An example of `use` declarations:
806806

807807
~~~~
808+
use foo = core::info;
808809
use core::float::sin;
809810
use core::str::{slice, to_upper};
810811
use core::option::Some;
811812
812813
fn main() {
813-
// Equivalent to 'info!(core::float::sin(1.0));'
814-
info!(sin(1.0));
814+
// Equivalent to 'log(core::info, core::float::sin(1.0));'
815+
log(foo, sin(1.0));
815816
816-
// Equivalent to 'info!(core::option::Some(1.0));'
817-
info!(Some(1.0));
817+
// Equivalent to 'log(core::info, core::option::Some(1.0));'
818+
log(info, Some(1.0));
818819
819-
// Equivalent to
820-
// 'info!(core::str::to_upper(core::str::slice("foo", 0, 1)));'
821-
info!(to_upper(slice("foo", 0, 1)));
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)));
822823
}
823824
~~~~
824825

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

990991
~~~~
991992
fn my_err(s: &str) -> ! {
992-
info!(s);
993+
log(info, s);
993994
fail!();
994995
}
995996
~~~~
@@ -2396,6 +2397,58 @@ fn max(a: int, b: int) -> int {
23962397
}
23972398
~~~~
23982399

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+
23992452

24002453
# Type system
24012454

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

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

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

branches/auto/doc/tutorial.md

Lines changed: 2 additions & 2 deletions
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) => info!(a + b + (c as int))
747+
(a, b, c) => log(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) => info!(a + b + (c as int))
763+
MyTup(a, b, c) => log(info, a + b + (c as int))
764764
}
765765
~~~~
766766

branches/auto/src/compiletest/util.rs

Lines changed: 1 addition & 1 deletion
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-
debug!("%s", s);
49+
log(debug, s);
5050
if config.verbose { io::println(s); }
5151
}

branches/auto/src/libcore/core.rc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,14 @@ pub use clone::Clone;
216216
* more-verbosity. Error is the bottom level, default logging level is
217217
* warn-and-below.
218218
*/
219+
219220
/// The error log level
220-
#[cfg(stage0)]
221221
pub const error : u32 = 1_u32;
222222
/// The warning log level
223-
#[cfg(stage0)]
224223
pub const warn : u32 = 2_u32;
225224
/// The info log level
226-
#[cfg(stage0)]
227225
pub const info : u32 = 3_u32;
228226
/// The debug log level
229-
#[cfg(stage0)]
230227
pub const debug : u32 = 4_u32;
231228

232229

@@ -254,13 +251,9 @@ pub mod rt;
254251
// can be resolved within libcore.
255252
#[doc(hidden)] // FIXME #3538
256253
pub mod core {
257-
#[cfg(stage0)]
258254
pub const error : u32 = 1_u32;
259-
#[cfg(stage0)]
260255
pub const warn : u32 = 2_u32;
261-
#[cfg(stage0)]
262256
pub const info : u32 = 3_u32;
263-
#[cfg(stage0)]
264257
pub const debug : u32 = 4_u32;
265258

266259
pub use cmp;

branches/auto/src/libcore/io.rs

Lines changed: 6 additions & 5 deletions
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-
error!("%s", os::last_os_error());
686+
log(error, 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-
error!("%s", os::last_os_error());
736+
log(error, os::last_os_error());
737737
fail!();
738738
}
739739
count += nout as uint;
@@ -1288,6 +1288,7 @@ pub mod fsync {
12881288

12891289
#[cfg(test)]
12901290
mod tests {
1291+
use debug;
12911292
use i32;
12921293
use io::{BytesWriter, SeekCur, SeekEnd, SeekSet};
12931294
use io;
@@ -1300,10 +1301,10 @@ mod tests {
13001301
#[test]
13011302
fn test_simple() {
13021303
let tmpfile = &Path("tmp/lib-io-test-simple.tmp");
1303-
debug!(tmpfile);
1304+
log(debug, tmpfile);
13041305
let frood: ~str =
13051306
~"A hoopy frood who really knows where his towel is.";
1306-
debug!(copy frood);
1307+
log(debug, copy frood);
13071308
{
13081309
let out: io::Writer =
13091310
result::get(
@@ -1312,7 +1313,7 @@ mod tests {
13121313
}
13131314
let inp: io::Reader = result::get(&io::file_reader(tmpfile));
13141315
let frood2: ~str = inp.read_c_str();
1315-
debug!(copy frood2);
1316+
log(debug, copy frood2);
13161317
fail_unless!(frood == frood2);
13171318
}
13181319

branches/auto/src/libcore/os.rs

Lines changed: 20 additions & 18 deletions
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-
debug!("get_env_pairs: %s",
212-
env_pair);
211+
log(debug, fmt!("get_env_pairs: %s",
212+
env_pair));
213213
result.push(env_pair);
214214
});
215215
result
@@ -219,8 +219,9 @@ pub fn env() -> ~[(~str,~str)] {
219219
let mut pairs = ~[];
220220
for input.each |p| {
221221
let vs = str::splitn_char(*p, '=', 1);
222-
debug!("splitting: len: %u",
223-
vs.len());
222+
log(debug,
223+
fmt!("splitting: len: %u",
224+
vs.len()));
224225
fail_unless!(vs.len() == 2);
225226
pairs.push((copy vs[0], copy vs[1]));
226227
}
@@ -681,10 +682,10 @@ pub fn list_dir(p: &Path) -> ~[~str] {
681682
let input = p.to_str();
682683
let mut strings = ~[];
683684
let input_ptr = ::cast::transmute(&input[0]);
684-
debug!("os::list_dir -- BEFORE OPENDIR");
685+
log(debug, "os::list_dir -- BEFORE OPENDIR");
685686
let dir_ptr = opendir(input_ptr);
686687
if (dir_ptr as uint != 0) {
687-
debug!("os::list_dir -- opendir() SUCCESS");
688+
log(debug, "os::list_dir -- opendir() SUCCESS");
688689
let mut entry_ptr = readdir(dir_ptr);
689690
while (entry_ptr as uint != 0) {
690691
strings.push(
@@ -696,11 +697,11 @@ pub fn list_dir(p: &Path) -> ~[~str] {
696697
closedir(dir_ptr);
697698
}
698699
else {
699-
debug!("os::list_dir -- opendir() FAILURE");
700+
log(debug, "os::list_dir -- opendir() FAILURE");
700701
}
701-
debug!(
702-
"os::list_dir -- AFTER -- #: %?",
703-
strings.len());
702+
log(debug,
703+
fmt!("os::list_dir -- AFTER -- #: %?",
704+
strings.len()));
704705
strings
705706
}
706707
#[cfg(windows)]
@@ -1257,6 +1258,7 @@ pub mod consts {
12571258
#[cfg(test)]
12581259
#[allow(non_implicitly_copyable_typarams)]
12591260
mod tests {
1261+
use debug;
12601262
use libc::{c_int, c_void, size_t};
12611263
use libc;
12621264
use option::{None, Option, Some};
@@ -1272,7 +1274,7 @@ mod tests {
12721274
12731275
#[test]
12741276
pub fn last_os_error() {
1275-
debug!(os::last_os_error());
1277+
log(debug, os::last_os_error());
12761278
}
12771279
12781280
#[test]
@@ -1318,7 +1320,7 @@ mod tests {
13181320
while i < 100 { s += ~"aaaaaaaaaa"; i += 1; }
13191321
let n = make_rand_name();
13201322
setenv(n, s);
1321-
debug!(copy s);
1323+
log(debug, copy s);
13221324
fail_unless!(getenv(n) == option::Some(s));
13231325
}
13241326
@@ -1327,7 +1329,7 @@ mod tests {
13271329
let path = os::self_exe_path();
13281330
fail_unless!(path.is_some());
13291331
let path = path.get();
1330-
debug!(copy path);
1332+
log(debug, copy path);
13311333
13321334
// Hard to test this function
13331335
fail_unless!(path.is_absolute);
@@ -1340,7 +1342,7 @@ mod tests {
13401342
fail_unless!(vec::len(e) > 0u);
13411343
for vec::each(e) |p| {
13421344
let (n, v) = copy *p;
1343-
debug!(copy n);
1345+
log(debug, copy n);
13441346
let v2 = getenv(n);
13451347
// MingW seems to set some funky environment variables like
13461348
// "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned
@@ -1365,10 +1367,10 @@ mod tests {
13651367
fn test() {
13661368
fail_unless!((!Path("test-path").is_absolute));
13671369
1368-
debug!(~"Current working directory: " + getcwd().to_str());
1370+
log(debug, ~"Current working directory: " + getcwd().to_str());
13691371
1370-
debug!(make_absolute(&Path("test-path")));
1371-
debug!(make_absolute(&Path("/usr/bin")));
1372+
log(debug, make_absolute(&Path("test-path")));
1373+
log(debug, make_absolute(&Path("/usr/bin")));
13721374
}
13731375
13741376
#[test]
@@ -1431,7 +1433,7 @@ mod tests {
14311433
fail_unless!((vec::len(dirs) > 0u));
14321434
14331435
for vec::each(dirs) |dir| {
1434-
debug!(copy *dir);
1436+
log(debug, copy *dir);
14351437
}
14361438
}
14371439

branches/auto/src/libcore/prelude.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,18 @@ 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)