record
import std::log::record; · source
A log record and its level: what a Logger hands a LogSink.
Types
LogLevel
type enum LogLevel with [Eq, Clone, Debug] {
Error;
Warning;
Information;
Debug;
Trace;
}
How much a record matters, from Error, the most, to Trace, the least. A level setting lets through records at that level and every level above it: Warning passes errors and warnings, which allows answers — LogLevel::Warning.allows(&LogLevel::Error) is true.
parse reads a level's name ignoring ASCII case — error, warning, information, debug or trace — and name writes it in lower case, as Display does.
Variants
| Variant |
|---|
Error |
Warning |
Information |
Debug |
Trace |
Constructors
static parse(name: Str) -> Option<LogLevel>;
static parse(name: Str) -> Option<LogLevel>;The level a name spells, ignoring ASCII case: error, warning, information, debug or trace; None for any other text.
Methods
name(&this) -> Str;
name(&this) -> Str;The level's name, in lower case, as parse reads it.
allows(&this, level: &LogLevel) -> boolean;
allows(&this, level: &LogLevel) -> boolean;True when a setting of this lets a record at level through.
Trait implementations
implement trait Display for enum LogLevel
LogRecord
type struct LogRecord {
level: LogLevel;
area: Str;
message: Arguments;
location: Location;
time: SystemTime;
}
One thing logged: its level, the area of the Logger that logged it, the message, where the logging call is written, and when it was made. The message is an Arguments that borrows the values the logging call was given, so it is formatted only during the LogSink.write call the record is passed to, never after.
Properties
| Property | Type | Notes |
|---|---|---|
level | LogLevel | |
area | Str | The area of the Logger that logged it. |
message | Arguments | |
location | Location | Where the logging call is written. |
time | SystemTime |
type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type enum Name {
Unit,
Payload(T),
Named { x: i32 },
}An algebraic data type. Variants may be bare or carry a tuple or struct payload, and a match on an enum must cover every variant. Name::Variant names a variant; methods are added with implement enum Name { ... }.
type enum LogLevel with [Eq, Clone, Debug] {
Error;
Warning;
Information;
Debug;
Trace;
}How much a record matters, from Error, the most, to Trace, the least. A level setting lets through records at that level and every level above it: Warning passes errors and warnings.
type struct Point with [Eq, Clone, Debug] { .. }Asks the compiler to generate implementations of the listed traits for the type, each working through its fields or variants in declaration order. The derivable traits are Eq, Ord, Hash, Clone, Debug, Default, ToValue and FromValue, and the text formats' FromJson, ToJson, FromYaml, ToYaml, FromToml and ToToml. The clause comes after the name and its parameters, before where.
type trait Eq<Rhs = This> {
equals(&this, other: &Rhs) -> boolean;
}Types that support value equality with a value of Rhs, which is the type itself unless an implementation names another: implement trait Eq for Str compares two Strs, and implement trait Eq<string> for Str a Str with a string.
type trait Clone {
clone(&this) -> This;
}A type whose values can be duplicated into independent copies. A type takes it with with [Clone] on its declaration, or by implementing clone by hand.
type trait Debug {
fmt(&this, f: mut &Formatter) -> Result<(), FormatError>;
}How a value reads to a programmer: what {x:?} writes, and {x:#?} over several lines. with [Debug] on a declaration writes it field by field.
LogLevel::ErrorLogLevel::WarningLogLevel::InformationLogLevel::DebugLogLevel::Tracetype struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct LogRecord {
level: LogLevel;
area: Str;
message: Arguments;
location: Location;
time: SystemTime;
}One thing logged. The message is formatted only when a sink writes it, and only during the LogSink.write call the record is passed to: it borrows the values the logging call was given.
LogRecord.level: LogLeveltype enum LogLevel with [Eq, Clone, Debug] {
Error;
Warning;
Information;
Debug;
Trace;
}How much a record matters, from Error, the most, to Trace, the least. A level setting lets through records at that level and every level above it: Warning passes errors and warnings.
LogRecord.area: StrThe area of the Logger that logged it.
type struct Str {}A read-only view of UTF-8 text owned elsewhere: a string literal, a String, a file's bytes. Copying a Str copies the view, not the text, and it is valid only while what it views is. Str::new("text") views a literal; String.as_str() views a String.
LogRecord.message: Argumentstype struct Arguments {}Text formatted where it is written. An f-string written directly as an argument whose parameter has this type is not built into a String: it becomes the f-string's pieces - its literal text, and a borrow of each hole's value - and the callee writes them through a Formatter (FormatWrite.write), each hole…
LogRecord.location: LocationWhere the logging call is written.
type struct Location {}A place in the source: the file as the build was given it, the line and column (both from 1), and the readable qualified name of the function the place is in.
std::core::intrinsicsLogRecord.time: SystemTimetype struct SystemTime {}A measurement of the wall clock (CLOCK_REALTIME) as a raw timespec. duration_since_epoch() yields a Unix timestamp. Subject to NTP steps and manual changes; do not use for elapsed-time measurement. POD.
import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
namespace std::log;log: records a program writes about what it is doing, by area and level, sent to one process-wide sink.
module pageLogLevel::ErrorLogLevel::TraceLogLevel::WarningLogLevel::allows(&this, level: &LogLevel) -> booleanTrue when a setting of this lets a record at level through.
trueThe boolean literal. Booleans are a distinct 1-byte type, not interchangeable with integers; if and while conditions must be boolean.
static LogLevel::parse(name: Str) -> Option<LogLevel>The level a name spells, ignoring ASCII case: error, warning, information, debug or trace; None for any other text.
type trait Display {
fmt(&this, f: mut &Formatter) -> Result<(), FormatError>;
to_string(&this) -> String;
}How a value reads to a person: what {x} in an f-string and println write. Implement it for a type a user sees.
LogLevel::InformationLogLevel::Debugstatic name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
(parameter) name: Strtype enum Option<T> with [Eq, Clone, Debug] {
Some(T);
None;
}A value of type T that may be absent: Some(value) or None.
Option::None&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
(parameter) level: &LogLevelLogRecord.level: LogLevelimplement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referenceimplement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language referencetype struct Logger {}A named area of a program, Logger::new("http"), that logs records at a level: log.warning(f"no route for {path}"). An f-string message is formatted only when a sink writes it, so a record the settings refuse costs one atomic load. A logger is a name and nothing else: copy it, or keep one in a global.
type trait LogSink {
write(&this, record: &LogRecord) -> void;
}A destination for log records. Logging calls write for every record that passes the level settings, one call at a time: no two writes to a sink overlap, so a sink needs no lock of its own for its output to come out whole.
LogRecord.message: ArgumentsLogRecord.time: SystemTime