xur_

> module

std::log

structured logging

use std::log; feature log in the browser (in-memory)

std::log emits log events through the tracing crate. Configure a subscriber with subscriber(), install it with init(), then log with trace, debug, info, warn and error. Until a subscriber is installed, events go nowhere unless the host program set one up.

> functions

# debug(format: str, args?: any)

Emits an event at that level, with the message formatted as by fmt::format. With no args the message is used as is.

# error(format: str, args?: any)

Emits an event at that level, with the message formatted as by fmt::format. With no args the message is used as is.

# info(format: str, args?: any)

Emits an event at that level, with the message formatted as by fmt::format. With no args the message is used as is.

# subscriber() -> SubscriberBuilder

A new builder with the defaults: level info, the full format on stderr, targets and ANSI colours on, file names and line numbers off.

# trace(format: str, args?: any)

Emits an event at that level, with the message formatted as by fmt::format. With no args the message is used as is.

# warn(format: str, args?: any)

Emits an event at that level, with the message formatted as by fmt::format. With no args the message is used as is.

> types

┌ struct Level

An opaque value; see the functions that return it.

┌ type SubscriberBuilder

Each method except init returns a new builder; the original is unchanged.

The builder exposed to xur scripts as a native object.

# subscriber_builder.compact() -> SubscriberBuilder

Writes events as JSON lines, in the multi-line pretty format, or in the compact single-line format.

# subscriber_builder.init()

Installs the subscriber for the whole process. It is a runtime error if a subscriber is already installed or the log file can't be opened.

# subscriber_builder.json() -> SubscriberBuilder

Writes events as JSON lines, in the multi-line pretty format, or in the compact single-line format.

# subscriber_builder.pretty() -> SubscriberBuilder

Writes events as JSON lines, in the multi-line pretty format, or in the compact single-line format.

# subscriber_builder.to_file(path: str) -> SubscriberBuilder

Appends output to the file at path, creating it if needed, instead of writing to stderr.

# subscriber_builder.to_stderr() -> SubscriberBuilder

Writes output to stderr (the default).

# subscriber_builder.truncate() -> SubscriberBuilder

With to_file, empties the file when the subscriber is installed.

# subscriber_builder.with_ansi(v: bool) -> SubscriberBuilder

Turns ANSI colours on or off. Output to a file never has colours.

# subscriber_builder.with_file(v: bool) -> SubscriberBuilder

Shows or hides the source file and line number.

# subscriber_builder.with_filter(filter: str) -> SubscriberBuilder

Filters events with a tracing EnvFilter directive such as "debug,xur_std::log=info", instead of the max level. Directives also apply to Rust code logging in the same process, such as a stub's host. If the RUST_LOG environment variable is set, it is used instead.

# subscriber_builder.with_line_number(v: bool) -> SubscriberBuilder

Shows or hides the source file and line number.

# subscriber_builder.with_max_level(level: Level | str) -> SubscriberBuilder

Logs events at level and above. level is a Level or one of the strings "trace", "debug", "info", "warn" and "error"; anything else is a runtime error.

# subscriber_builder.with_target(v: bool) -> SubscriberBuilder

Shows or hides each event's target. Events from scripts all have the target xur_std::log.

> level

log::Level is an enum of severities, lowest first: Trace, Debug, Info, Warn and Error.

> examples

use std::log;
use std::io;

fn main() {
    log::subscriber()
        .with_max_level(log::Level::Debug)
        .with_ansi(true)
        .init();

    log::info("application started");
    log::debug("value: {}", 42);
    log::warn("something to watch");
}