birch/record

Log record representation.

A LogRecord captures all information about a single log event: timestamp, level, logger name, message, and metadata.

Types

A log record representing a single log event.

pub type LogRecord {
  LogRecord(
    timestamp: String,
    level: level.Level,
    logger_name: String,
    message: String,
    metadata: List(#(String, String)),
    caller_id: option.Option(String),
  )
}

Constructors

  • LogRecord(
      timestamp: String,
      level: level.Level,
      logger_name: String,
      message: String,
      metadata: List(#(String, String)),
      caller_id: option.Option(String),
    )

    Arguments

    timestamp

    When the log event occurred (ISO 8601 timestamp)

    level

    Severity level of the log event

    logger_name

    Name of the logger that produced this record

    message

    The log message

    metadata

    Key-value metadata attached to this record

    caller_id

    Optional caller process/thread ID for debugging concurrent applications. On Erlang: String representation of the calling process PID. On JavaScript: “main” for main thread, or worker ID if available.

Metadata is a list of key-value pairs attached to a log record. Keys and values are both strings for simplicity and cross-target compatibility.

pub type Metadata =
  List(#(String, String))

Values

pub fn get_caller_id(record: LogRecord) -> option.Option(String)

Get the caller ID from a log record, if set.

pub fn get_metadata(
  record: LogRecord,
  key: String,
) -> Result(String, Nil)

Get a metadata value by key.

pub fn new(
  timestamp timestamp: String,
  level level: level.Level,
  logger_name logger_name: String,
  message message: String,
  metadata metadata: List(#(String, String)),
) -> LogRecord

Create a new log record with the given parameters. The caller_id field defaults to None. Use with_caller_id to set it.

pub fn with_caller_id(
  record: LogRecord,
  caller_id: String,
) -> LogRecord

Set the caller ID on a log record. The caller ID identifies the process or thread that created the log.

pub fn with_metadata(
  record: LogRecord,
  metadata: List(#(String, String)),
) -> LogRecord

Add metadata to a log record. New metadata is prepended, allowing later entries to shadow earlier ones.

Search Document