@@ -3046,7 +3046,51 @@ Executing a @code{log} expression may, depending on runtime configuration,
3046
3046
cause a value to be appended to an internal diagnostic logging buffer provided
3047
3047
by the runtime or emitted to a system console. Log expressions are enabled or
3048
3048
disabled dynamically at run-time on a per-task and per-item
3049
- basis. @xref {Ref.Run.Log }.
3049
+ basis. @xref {Ref.Run.Log }.
3050
+
3051
+ Each @code {log } expression must be provided with a @emph {level } argument in
3052
+ addition to the value to log. The logging level is a @code {u32 } value, where
3053
+ lower levels indicate more-urgent levels of logging. By default, the lowest
3054
+ four logging levels (@code {0_u32 ... 3_u32 }) are predefined as the constants
3055
+ @code {error }, @code {warn }, @code {info } and @code {debug } in the @code {core }
3056
+ library.
3057
+
3058
+ Additionally, the macros @code {#error }, @code {#warn }, @code {#info } and
3059
+ @code {#debug } are defined in the default syntax-extension namespace. These
3060
+ expand into calls to the logging facility composed with calls to the
3061
+ @code {#fmt } string formatting syntax-extension.
3062
+
3063
+ The following examples all produce the same output, logged at the @code {error }
3064
+ logging level:
3065
+
3066
+ @example
3067
+ // Full version, logging a value.
3068
+ log(core::error, "file not found: " + filename);
3069
+
3070
+ // Log-level abbreviated, since core::* is imported by default.
3071
+ log(error, "file not found: " + filename);
3072
+
3073
+ // Formatting the message using a format-string and #fmt
3074
+ log(error, #fmt("file not found: %s", filename));
3075
+
3076
+ // Using the #error macro, that expands to the previous call.
3077
+ #error("file not found: %s", filename);
3078
+ @end example
3079
+
3080
+ A @code {log } expression is @emph {not evaluated } when logging at the specified
3081
+ logging-level, module or task is disabled at runtime. This makes inactive
3082
+ @code {log } expressions very cheap; they should be used extensively in Rust
3083
+ code, as diagnostic aids, as they add little overhead beyond a single
3084
+ integer-compare and branch at runtime.
3085
+
3086
+ Logging is presently implemented as a language built-in feature, as it makes
3087
+ use of compiler-provided logic for allocating the associated per-module
3088
+ logging-control structures visible to the runtime, and lazily evaluating
3089
+ arguments. In the future, as more of the supporting compiler-provided logic is
3090
+ moved into libraries, logging is likely to move to a component of the core
3091
+ library. It is best to use the macro forms of logging (@emph {#error },
3092
+ @emph {#debug }, etc.) to minimize disruption to code using the logging facility
3093
+ when it is changed.
3050
3094
3051
3095
@example
3052
3096
@end example
0 commit comments