distribute/log

Types

Logger configuration

pub type Config {
  Config(
    level: Level,
    enable_colors: Bool,
    enable_timestamps: Bool,
  )
}

Constructors

  • Config(
      level: Level,
      enable_colors: Bool,
      enable_timestamps: Bool,
    )

Log levels from most verbose to least verbose

pub type Level {
  Debug
  Info
  Warn
  Error
  Off
}

Constructors

  • Debug
  • Info
  • Warn
  • Error
  • Off

Structured log entry with metadata

pub type LogEntry {
  LogEntry(
    Level,
    String,
    List(#(String, String)),
    option.Option(String),
    Int,
  )
}

Constructors

Values

pub fn debug(
  message: String,
  metadata: List(#(String, String)),
) -> Nil

Log a debug message

pub fn debug_with_correlation(
  message: String,
  metadata: List(#(String, String)),
  correlation_id: String,
) -> Nil

Log a debug message with correlation ID

pub fn disable_logging() -> Nil

Disable all logging output (useful for tests)

pub fn enable_logging() -> Nil

Enable logging output

pub fn error(
  message: String,
  metadata: List(#(String, String)),
) -> Nil

Log an error message

pub fn error_with_correlation(
  message: String,
  metadata: List(#(String, String)),
  correlation_id: String,
) -> Nil

Log an error message with correlation ID

pub fn format_log_entry(entry: LogEntry) -> String

Format a log entry as a string

pub fn generate_correlation_id() -> String

Generate a new correlation ID

pub fn get_level() -> Level

Get the current minimum log level

pub fn info(
  message: String,
  metadata: List(#(String, String)),
) -> Nil

Log an info message

pub fn info_with_correlation(
  message: String,
  metadata: List(#(String, String)),
  correlation_id: String,
) -> Nil

Log an info message with correlation ID

pub fn log(
  level: Level,
  message: String,
  metadata: List(#(String, String)),
  correlation_id: option.Option(String),
) -> Nil

Core logging function

pub fn set_backend(backend: String) -> Nil

Set the logging backend implementation used to handle output. Use “console” (default) or “erlang_logger”.

pub fn set_level(level: Level) -> Nil

Set the minimum log level Messages below this level will not be logged

pub fn warn(
  message: String,
  metadata: List(#(String, String)),
) -> Nil

Log a warning message

pub fn warn_with_correlation(
  message: String,
  metadata: List(#(String, String)),
  correlation_id: String,
) -> Nil

Log a warning message with correlation ID

pub fn with_correlation_id(id: String, f: fn() -> a) -> a

Execute a function with a specific correlation ID

Search Document