viva_telemetry/log/handler

Handler interface for log outputs

Handlers receive log entries and output them somewhere:

Types

Console handler configuration

pub type ConsoleConfig {
  ConsoleConfig(
    level: level.Level,
    colored: Bool,
    stderr_for_errors: Bool,
  )
}

Constructors

  • ConsoleConfig(
      level: level.Level,
      colored: Bool,
      stderr_for_errors: Bool,
    )

    Arguments

    level

    Minimum level to log

    colored

    Use ANSI colors

    stderr_for_errors

    Output to stderr for errors (else stdout)

Custom handler configuration

pub type CustomConfig {
  CustomConfig(
    level: level.Level,
    handler_fn: fn(entry.Entry) -> Nil,
  )
}

Constructors

  • CustomConfig(
      level: level.Level,
      handler_fn: fn(entry.Entry) -> Nil,
    )

    Arguments

    level

    Minimum level to log

    handler_fn

    Custom handler function

File handler configuration

pub type FileConfig {
  FileConfig(
    level: level.Level,
    path: String,
    rotation: Rotation,
  )
}

Constructors

  • FileConfig(level: level.Level, path: String, rotation: Rotation)

    Arguments

    level

    Minimum level to log

    path

    File path

    rotation

    Rotation strategy

Handler configuration

pub type Handler {
  ConsoleHandler(config: ConsoleConfig)
  JsonHandler(config: JsonConfig)
  FileHandler(config: FileConfig)
  CustomHandler(config: CustomConfig)
}

Constructors

  • ConsoleHandler(config: ConsoleConfig)

    Console handler - outputs to stdout/stderr

  • JsonHandler(config: JsonConfig)

    JSON handler - outputs structured JSON to file

  • FileHandler(config: FileConfig)

    File handler - outputs plain text to file

  • CustomHandler(config: CustomConfig)

    Custom handler - user-provided function

JSON handler configuration

pub type JsonConfig {
  JsonConfig(level: level.Level, path: String, pretty: Bool)
}

Constructors

  • JsonConfig(level: level.Level, path: String, pretty: Bool)

    Arguments

    level

    Minimum level to log

    path

    File path

    pretty

    Pretty print JSON

File rotation strategies

pub type Rotation {
  NoRotation
  Daily
  Size(max_bytes: Int)
  KeepN(n: Int, strategy: Rotation)
}

Constructors

  • NoRotation

    No rotation

  • Daily

    Rotate daily

  • Size(max_bytes: Int)

    Rotate when file exceeds size (bytes)

  • KeepN(n: Int, strategy: Rotation)

    Keep N rotated files

Values

pub fn console() -> Handler

Default console handler (Info level, colored)

pub fn console_with_level(lvl: level.Level) -> Handler

Console handler with custom level

pub fn custom(
  lvl: level.Level,
  handler_fn: fn(entry.Entry) -> Nil,
) -> Handler

Custom handler

pub fn file(path: String) -> Handler

File handler

pub fn file_with_rotation(
  path: String,
  rotation: Rotation,
) -> Handler

File handler with rotation

pub fn get_level(handler: Handler) -> level.Level

Get handler’s minimum level

pub fn json(path: String) -> Handler

JSON handler

pub fn json_with_level(path: String, lvl: level.Level) -> Handler

JSON handler with level

pub fn should_log(
  handler: Handler,
  log_level: level.Level,
) -> Bool

Check if handler should process this level

Search Document