spruce/severity

Generic Birch-style severity/status formatting.

Types

Controls how a Severity is rendered: its style (label, badge, simple, or custom), whether icons are shown, the glyph mode, and the padding width. Construct one with label, badge, simple, or custom.

pub opaque type Formatter

Birch-compatible severity levels, in ascending order.

pub type Severity {
  Trace
  Debug
  Info
  Notice
  Warn
  Err
  Critical
  Alert
  Fatal
}

Constructors

  • Trace
  • Debug
  • Info
  • Notice
  • Warn
  • Err
  • Critical
  • Alert
  • Fatal

Values

pub fn badge() -> Formatter

Render an uppercase bracketed severity badge, e.g. [WARN].

pub fn custom(
  render: fn(Severity, spruce.Spruce) -> String,
  target_width target_width: Int,
) -> Formatter

Render severities with a caller-supplied function.

pub fn icons(formatter: Formatter, enabled: Bool) -> Formatter

Enable or disable icons for formatters that support them.

pub fn label() -> Formatter

Render an icon plus lowercase severity label, e.g. ℹ info.

pub fn mode(formatter: Formatter, mode: symbol.Mode) -> Formatter

Set the glyph mode used by icon-bearing formatters.

pub fn render(
  sp: spruce.Spruce,
  formatter: Formatter,
  severity: Severity,
) -> String

Render a severity with the supplied formatter.

pub fn render_padded(
  sp: spruce.Spruce,
  formatter: Formatter,
  severity: Severity,
) -> String

Render a severity and pad it to the formatter’s visual target width.

pub fn simple() -> Formatter

Render an uppercase severity name, e.g. DEBUG.

pub fn target_width(formatter: Formatter) -> Int

Return the visual target width used by render_padded.

pub fn to_int(severity: Severity) -> Int

Convert a severity to its Birch ordering integer.

pub fn to_string(severity: Severity) -> String

Convert a severity to its uppercase label.

pub fn to_string_lowercase(severity: Severity) -> String

Convert a severity to its lowercase label.

Search Document