glogg/handler

Types

pub opaque type Handler

Values

pub fn add(handler: Handler) -> Nil

Adds a handler to the logging system.

On the Erlang target, the handler id is an atom, which means creating too many handlers can exhaust the atom table. That can lead to system instability. It’s recommended to create a limited number of handlers and reuse them.

Example

let my_handler = handler.new("my_handler_id")
  |> handler.with_minimal_level(level.Info)

handler.add(my_handler)
pub fn get_id(handler: Handler) -> String

Retrieves the ID of a handler.

pub fn new(id: String) -> Handler

Creates a new handler with the given ID and a default minimum level of Debug. The ID must be unique among all handlers.

Example

let my_handler = handler.new("my_handler_id")
pub fn remove(id: String) -> Nil

Removes a handler from the logging system by its ID.

Example

handler.remove("my_handler_id")
// or
handler.remove(my_handler |> handler.get_id())
pub fn set_default_handler_json_formatting() -> Nil

Sets the default handler to use JSON formatting.

pub fn set_default_handler_minimum_level(
  level: level.Level,
) -> Nil

Sets the minimum log level for the default handler.

pub fn set_handler_minimum_level(
  id: String,
  level: level.Level,
) -> Nil

Sets the minimum log level for a specific handler by its ID. This can be used to change the log level of an existing handler.

Example

handler.set_handler_minimum_level("my_handler_id", level.Warning)
// or
handler.set_handler_minimum_level(my_handler |> handler.get_id(), level.Warning)
pub fn set_primary_minimum_level(level: level.Level) -> Nil

Sets the global primary log level for the Erlang backend.

Messages below this level are discarded before reaching any handlers. The default level is Notice. This is a no-op on the JavaScript target.

pub fn setup_default_handler() -> Nil

Sets up the default handler with JSON formatting and a minimum level of Debug. Also sets the global primary minimum level to Debug. This is a convenience function for quick setup.

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

Creates a new handler with the given minimum level.

Example

let my_handler = handler.new("my_handler_id")
  |> handler.with_minimal_level(level.Info)
Search Document