log
Records a program writes about what it is doing, by area and level, sent to one process-wide sink. Not auto-imported.
A Logger names an area and logs at a LogLevel. Logging holds the settings every logger reads — a level for each area and the default one — and the LogSink records go to, which is StandardErrorSink until a program sets its own.
import std::collections::str::{ Str };
import std::log::logger::{ Logger, Logging };
const log: Logger = Logger::new(Str::new("http"));
function main() -> i32 {
Logging::configure_from_environment(Str::new("APP_LOG")).unwrap();
log.information(f"listening on port {8080}");
return 0;
}
With APP_LOG=information, that writes 2026-11-09T14:03:07Z information http: listening on port 8080 to standard error; with it unset, only warnings and errors are written.
The message is an f-string passed as an fmt::Arguments, so it is formatted only when a sink writes it: a record the settings refuse costs one atomic load, and its holes are never rendered.
module log::record;
module log::sink;
module log::logger;
export std::log::record::{ LogLevel, LogRecord };
export std::log::sink::{ LogSink, StandardErrorSink };
export std::log::logger::{ LogSpecificationError, Logger, Logging };
| File | What it holds | Import |
|---|---|---|
record | LogLevel, LogRecord | import std::log::record; |
sink | LogSink, StandardErrorSink | import std::log::sink; |
logger | Logger, Logging, LogSpecificationError | import std::log::logger; |
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).
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.
namespace std::log;log: records a program writes about what it is doing, by area and level, sent to one process-wide sink.
module pagenamespace std::log::logger;Logger, a named area a program logs through, and Logging, the process-wide settings every logger reads: the level for each area and the sink records go to.
type 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 struct Logging {}The process-wide logging settings. Records at Warning and above go to standard error until a program says otherwise.
const NAME: Type = value;At module level, a true compile-time constant, conventionally SCREAMING_SNAKE_CASE. (mut at module level declares mutable global state instead.)
const log: Loggerstatic Logger::new(area: Str) -> LoggerA logger for area, a name like http or http::server; an area below another (http::server below http) takes the level set for it when it has none of its own. The logger keeps the Str, not a copy, so the text must outlive it, as a literal does.
static Str::new(text: string) -> StrConstruct from a NUL-terminated C-style string literal. The caller certifies that text is valid UTF-8 and outlives this view. The NUL terminator is not included in the view.
function name<T>(param: Type) -> Ret { ... }Declares a function. Parameters are written name: Type and are never inferred; the return type follows -> and defaults to void. Declaration order does not matter: every signature is collected before any body is checked, so functions may call each other freely and recurse.
function main() -> i32static Logging::configure_from_environment(variable: Str) -> Result<(), LogSpecificationError>configure with the value of the environment variable variable; nothing changes when it is unset.
Result::unwrap(this) -> TThe Ok value, aborting on Err. Consumes the result: the value moves out to the caller and the error, if any, is released.
const log: LoggerLogger::information(&this, message: Arguments) -> voidlog at LogLevel::Information: what the program is doing. Refused until the settings allow Information for this area.
return value;Leaves the current function with the given value. A function whose return type is not void must return one; a bare return; is for void. In an async function it completes the future with the value.
module collections::array;
module { a::b; a::c; }
internal module a::detail;In a directory's _module.cryo aggregator, declares a submodule. A module is public; internal module keeps it and everything it declares to its own package. The line is structure only: reaching the child's names still takes an import or an export.
namespace std::log::sink;Where log records go: the LogSink trait, and StandardErrorSink, the sink logging writes to until a program sets its own.
export a::b::Name;
export a::b::{ X, Y as Z };Passes a name this module did not declare on to its importers, exactly as if they had imported the same path - how an aggregator presents a flat surface over its files. Every hop is explicit, and there is no glob form.
language referencetype 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 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.
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.
type struct StandardErrorSink {}Writes each record to standard error as one line, its time in RFC 3339 (UTC, to the second), its level, its area and its message:
std::log::sinktype struct LogSpecificationError with [Eq, Clone, Debug] {
entry: String;
}A logging specification entry Logging::configure could not read.