Struct Record Copy item path Source pub struct Record<'a> { }Expand description The “payload” of a log message.
§ Use
Record structures are passed as parameters to the log
method of the Log trait. Logger implementors manipulate these
structures in order to display log messages. Records are automatically
created by the log! macro and so are not seen by log users.
Note that the level() and target() accessors are equivalent to
self.metadata().level() and self.metadata().target() respectively.
These methods are provided as a convenience for users of this structure.
§ Example
The following example shows a simple logger that displays the level,
module path, and message of any Record that is passed to it.
struct SimpleLogger;
impl log::Log for SimpleLogger {
fn enabled(& self , _metadata: & log::Metadata) -> bool {
true
}
fn log(& self , record: & log::Record) {
if !self .enabled(record.metadata()) {
return ;
}
println! ("{}:{} -- {}" ,
record.level(),
record.target(),
record.args());
}
fn flush(& self ) {}
}37 fn msg(& self , record: & Record) -> Box<dyn Send + Sync + std::fmt::Display> {
38 Box::new(format! (
39 "{} {}/{}:{} {}" ,
40 record.level(),
41 std::thread::current().name().unwrap_or_default(),
42 record.file().unwrap_or("" ),
43 record.line().unwrap_or(0 ),
44 record.args ()
45 ))
46 }More examples Hide additional examples
examples/custom-format.rs (
line 24 )
18 fn msg(& self , record: & Record) -> Box<dyn Send + Sync + std::fmt::Display> {
19 Box::new(Msg {
20 level: record.level(),
21 thread: std::thread::current().name().map(|n| n.to_string()),
22 file: record.file_static(),
23 line: record.line(),
24 args: format! ("{}" , record.args ()),
25 module_path: record.module_path_static(),
26 })
27 }Metadata about the log directive.
The verbosity level of the message.
37 fn msg(& self , record: & Record) -> Box<dyn Send + Sync + std::fmt::Display> {
38 Box::new(format! (
39 "{} {}/{}:{} {}" ,
40 record.level (),
41 std::thread::current().name().unwrap_or_default(),
42 record.file().unwrap_or("" ),
43 record.line().unwrap_or(0 ),
44 record.args()
45 ))
46 }More examples Hide additional examples
examples/custom-format.rs (
line 20 )
18 fn msg(& self , record: & Record) -> Box<dyn Send + Sync + std::fmt::Display> {
19 Box::new(Msg {
20 level: record.level (),
21 thread: std::thread::current().name().map(|n| n.to_string()),
22 file: record.file_static(),
23 line: record.line(),
24 args: format! ("{}" , record.args()),
25 module_path: record.module_path_static(),
26 })
27 }The name of the target of the directive.
The module path of the message.
The module path of the message, if it is a 'static string.
examples/custom-format.rs (
line 25 )
18 fn msg(& self , record: & Record) -> Box<dyn Send + Sync + std::fmt::Display> {
19 Box::new(Msg {
20 level: record.level(),
21 thread: std::thread::current().name().map(|n| n.to_string()),
22 file: record.file_static(),
23 line: record.line(),
24 args: format! ("{}" , record.args()),
25 module_path: record.module_path_static (),
26 })
27 }The source file containing the message.
37 fn msg(& self , record: & Record) -> Box<dyn Send + Sync + std::fmt::Display> {
38 Box::new(format! (
39 "{} {}/{}:{} {}" ,
40 record.level(),
41 std::thread::current().name().unwrap_or_default(),
42 record.file ().unwrap_or("" ),
43 record.line().unwrap_or(0 ),
44 record.args()
45 ))
46 }The source file containing the message, if it is a 'static string.
examples/custom-format.rs (
line 22 )
18 fn msg(& self , record: & Record) -> Box<dyn Send + Sync + std::fmt::Display> {
19 Box::new(Msg {
20 level: record.level(),
21 thread: std::thread::current().name().map(|n| n.to_string()),
22 file: record.file_static (),
23 line: record.line(),
24 args: format! ("{}" , record.args()),
25 module_path: record.module_path_static(),
26 })
27 }The line containing the message.
37 fn msg(& self , record: & Record) -> Box<dyn Send + Sync + std::fmt::Display> {
38 Box::new(format! (
39 "{} {}/{}:{} {}" ,
40 record.level(),
41 std::thread::current().name().unwrap_or_default(),
42 record.file().unwrap_or("" ),
43 record.line ().unwrap_or(0 ),
44 record.args()
45 ))
46 }More examples Hide additional examples
examples/custom-format.rs (
line 23 )
18 fn msg(& self , record: & Record) -> Box<dyn Send + Sync + std::fmt::Display> {
19 Box::new(Msg {
20 level: record.level(),
21 thread: std::thread::current().name().map(|n| n.to_string()),
22 file: record.file_static(),
23 line: record.line (),
24 args: format! ("{}" , record.args()),
25 module_path: record.module_path_static(),
26 })
27 }The structured key-value pairs associated with the message.
Performs copy-assignment from
source.
Read more Formats the value using the given formatter.
Read more Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from
self to
dest.
Read more Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From <T> for U chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.