glimt

Types

Generic Dispatcher the can dispatch a LogMessage with a given data type and errors of a given type (build in dispatchers use Dynamic as error type)

pub type Dispatcher(data, context, result_type) =
  fn(LogMessage(data, context, result_type)) -> Nil

Logger that can be use for logging of a LogMessage with possible additional data to one or more LoggerInstance

pub opaque type Logger(data, context)

A logger instance can be either Direct (logging in same process) or Actor (logging in a separate process)

pub type LoggerInstance(data, context) {
  Direct(
    name: Option(String),
    level_min_value: Int,
    dispatch: Dispatcher(data, context, Dynamic),
  )
  Actor(
    name: Option(String),
    level_min_value: Int,
    Subject(LogMessage(data, context, Dynamic)),
  )
}

Constructors

  • Direct(
      name: Option(String),
      level_min_value: Int,
      dispatch: Dispatcher(data, context, Dynamic),
    )
  • Actor(
      name: Option(String),
      level_min_value: Int,
      Subject(LogMessage(data, context, Dynamic)),
    )

Functions

pub fn append_instance(logger: Logger(a, b), instance: LoggerInstance(
    a,
    b,
  )) -> Logger(a, b)

Add an instance to the logger

pub fn debug(logger: Logger(a, b), message: String) -> Logger(
  a,
  b,
)

Log a message at DEBUG level

pub fn error(logger: Logger(a, b), message: String, error: Result(
    c,
    d,
  )) -> Logger(a, b)

Log a message at ERROR level with the provided Result

pub fn fatal(logger: Logger(a, b), message: String, error: Result(
    c,
    d,
  )) -> Logger(a, b)

Log a message at FATAL level with the provided Result

pub fn get_context(logger: Logger(a, b)) -> Option(b)

Get current context data for the logger

pub fn info(logger: Logger(a, b), message: String) -> Logger(a, b)

Log a message at INFO level

pub fn level(logger: Logger(a, b), level: LogLevel) -> Logger(
  a,
  b,
)

Set a new minimum level for the logger

pub fn log(logger: Logger(a, b), level: LogLevel, message: String) -> Logger(
  a,
  b,
)

Log a message at the provided level

pub fn log_error_with_data(logger: Logger(a, b), level: LogLevel, message: String, error: Result(
    c,
    d,
  ), data: a) -> Logger(a, b)

Log a message at the provided level together with the provided Result and data

pub fn log_with_data(logger: Logger(a, b), level: LogLevel, message: String, data: a) -> Logger(
  a,
  b,
)

Log a message at the provided level with some additional data

pub fn new(name: String) -> Logger(a, b)

Create a new logger with the name “anonymous” that accepts any LogLevel The Logger starts without any LoggerInstance

pub fn new_stdout(name: String) -> Logger(Nil, #(String, String))

Convenience method for getting a direct stdout logger with basic serialization that accepts all log levels

pub fn start_instance(name: String, level: LogLevel, dispatch: fn(
    LogMessage(a, b, Dynamic),
  ) -> Nil) -> Result(LoggerInstance(a, b), StartError)

Starts an actor instance that logs using the provided dispatcher and a specified level

pub fn stdout_anonymous_instance(level: LogLevel) -> LoggerInstance(
  a,
  b,
)

Create an unnamed direct stdout instance with basic serialization

pub fn stdout_instance(name: String, level: LogLevel) -> LoggerInstance(
  a,
  b,
)

Creates a direct stdout instance with basic serialization

pub fn trace(logger: Logger(a, b), message: String) -> Logger(
  a,
  b,
)

Log a message at TRACE level

pub fn warning(logger: Logger(a, b), message: String) -> Logger(
  a,
  b,
)

Log a message at WARNING level

pub fn with_context(logger: Logger(a, b), context: b) -> Logger(
  a,
  b,
)

Add context data to the logger

pub fn with_time_provider(logger: Logger(a, b), time_provider: fn() ->
    String) -> Logger(a, b)

Set the function used to get time. The function should return a string representation of the current time. Can be used to configure the date/time format

Search Document