@@ -212,7 +212,7 @@ do drop
212
212
else enum extern
213
213
false fn for
214
214
if impl
215
- let loop
215
+ let log loop
216
216
match mod mut
217
217
priv pub pure
218
218
ref return
@@ -805,20 +805,21 @@ Use declarations support a number of "convenience" notations:
805
805
An example of ` use ` declarations:
806
806
807
807
~~~~
808
+ use foo = core::info;
808
809
use core::float::sin;
809
810
use core::str::{slice, to_upper};
810
811
use core::option::Some;
811
812
812
813
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));
815
816
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));
818
819
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)));
822
823
}
823
824
~~~~
824
825
@@ -888,10 +889,10 @@ declared, in an angle-bracket-enclosed, comma-separated list following
888
889
the function name.
889
890
890
891
~~~~ {.xfail-test}
891
- fn iter<T>(seq: &[T], f: & fn(T)) {
892
+ fn iter<T>(seq: &[T], f: fn(T)) {
892
893
for seq.each |elt| { f(elt); }
893
894
}
894
- fn map<T, U>(seq: &[T], f: & fn(T) -> U) -> ~[U] {
895
+ fn map<T, U>(seq: &[T], f: fn(T) -> U) -> ~[U] {
895
896
let mut acc = ~[];
896
897
for seq.each |elt| { acc.push(f(elt)); }
897
898
acc
@@ -989,7 +990,7 @@ output slot type would normally be. For example:
989
990
990
991
~~~~
991
992
fn my_err(s: &str) -> ! {
992
- info!( s);
993
+ log(info, s);
993
994
fail!();
994
995
}
995
996
~~~~
@@ -1197,7 +1198,7 @@ These appear after the trait name, using the same syntax used in [generic functi
1197
1198
trait Seq<T> {
1198
1199
fn len() -> uint;
1199
1200
fn elt_at(n: uint) -> T;
1200
- fn iter(& fn(T));
1201
+ fn iter(fn(T));
1201
1202
}
1202
1203
~~~~
1203
1204
@@ -2073,7 +2074,7 @@ and moving values from the environment into the lambda expression's captured env
2073
2074
An example of a lambda expression:
2074
2075
2075
2076
~~~~
2076
- fn ten_times(f: & fn(int)) {
2077
+ fn ten_times(f: fn(int)) {
2077
2078
let mut i = 0;
2078
2079
while i < 10 {
2079
2080
f(i);
@@ -2176,7 +2177,7 @@ If the `expr` is a [field expression](#field-expressions), it is parsed as thoug
2176
2177
In this example, both calls to ` f ` are equivalent:
2177
2178
2178
2179
~~~~
2179
- # fn f(f: & fn(int)) { }
2180
+ # fn f(f: fn(int)) { }
2180
2181
# fn g(i: int) { }
2181
2182
2182
2183
f(|j| g(j));
@@ -2396,6 +2397,58 @@ fn max(a: int, b: int) -> int {
2396
2397
}
2397
2398
~~~~
2398
2399
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
+
2399
2452
2400
2453
# Type system
2401
2454
@@ -2702,7 +2755,7 @@ and the cast expression in `main`.
2702
2755
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
2703
2756
2704
2757
~~~~~~~
2705
- fn map<A: Copy, B: Copy>(f: & fn(A) -> B, xs: &[A]) -> ~[B] {
2758
+ fn map<A: Copy, B: Copy>(f: fn(A) -> B, xs: &[A]) -> ~[B] {
2706
2759
if xs.len() == 0 { return ~[]; }
2707
2760
let first: B = f(xs[0]);
2708
2761
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
@@ -3096,7 +3149,7 @@ communication facilities.
3096
3149
3097
3150
The runtime contains a system for directing [ logging
3098
3151
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.
3100
3153
3101
3154
Logging output is enabled by setting the ` RUST_LOG ` environment
3102
3155
variable. ` RUST_LOG ` accepts a logging specification made up of a
0 commit comments