spruce/severity

Erlang/OTP Logger and RFC 5424 severity 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

RFC 5424 / Erlang OTP Logger severity levels, in descending order of urgency.

pub type Severity {
  Emergency
  Alert
  Critical
  Error
  Warning
  Notice
  Info
  Debug
}

Constructors

  • Emergency
  • Alert
  • Critical
  • Error
  • Warning
  • Notice
  • Info
  • Debug

Values

pub fn badge() -> Formatter

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

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: spruce.SymbolMode,
) -> Formatter

Override the glyph mode used by icon-bearing formatters. By default the rendering context’s symbol mode is used; call this to pin a specific mode regardless of the context.

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

Render a severity with the supplied formatter.

pub fn render_padded(
  context: 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 RFC 5424 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