View Source ProcessHub.Service.LoggerService (ProcessHub v0.5.0-beta)

Logging service for ProcessHub with Drupal-style placeholder-based formatting.

Provides simple functions (no macros) for logging with automatic [ProcessHub] prefix and optional custom prefix support. Each log message includes metadata (current node) appended at the end.

Placeholder Syntax

Uses @key placeholders that are replaced with values from the replacements map:

LoggerService.error("Child @child_id failed", %{
  "child_id" => "my_child"
})
# => "[ProcessHub] Child my_child failed | node: :foo@bar"

Custom Prefix

Add a custom prefix after [ProcessHub] using the :prefix option:

LoggerService.warning("Timeout occurred", %{}, prefix: "Coordinator")
# => "[ProcessHub][Coordinator] Timeout occurred | node: :foo@bar"

Available Functions

All functions have the signature: level(message, replacements \\ %{}, opts \\ [])

Summary

Functions

Logs a debug message with optional placeholders and prefix.

Logs an error message with optional placeholders and prefix.

Formats a message with prefix, placeholder replacement, and metadata.

Logs an info message with optional placeholders and prefix.

Logs a notice message with optional placeholders and prefix.

Replaces @key placeholders in a message with values from the replacements map.

Logs a warning message with optional placeholders and prefix.

Functions

Link to this function

debug(message, replacements \\ %{}, opts \\ [])

View Source
@spec debug(String.t(), map(), keyword()) :: :ok

Logs a debug message with optional placeholders and prefix.

Parameters

  • message - The log message with optional @key placeholders
  • replacements - Map of placeholder keys to values (default: %{})
  • opts - Keyword list of options (default: [])
    • :prefix - Optional string to add after [ProcessHub]

Examples

LoggerService.debug("Processing @item", %{"item" => "foo"})
LoggerService.debug("Starting up", %{}, prefix: "Worker")
Link to this function

error(message, replacements \\ %{}, opts \\ [])

View Source
@spec error(String.t(), map(), keyword()) :: :ok

Logs an error message with optional placeholders and prefix.

Parameters

  • message - The log message with optional @key placeholders
  • replacements - Map of placeholder keys to values (default: %{})
  • opts - Keyword list of options (default: [])
    • :prefix - Optional string to add after [ProcessHub]

Examples

LoggerService.error("Failed to connect")
LoggerService.error("Process @pid crashed", %{"pid" => self()}, prefix: "Supervisor")
Link to this function

format_message(message, replacements, opts)

View Source
@spec format_message(String.t(), map(), keyword()) :: String.t()

Formats a message with prefix, placeholder replacement, and metadata.

Parameters

  • message - The log message with optional @key placeholders
  • replacements - Map of placeholder keys to values
  • opts - Keyword list of options
    • :prefix - Optional string to add after [ProcessHub]

Examples

iex> LoggerService.format_message("Hello @name", %{"name" => "World"}, [])
"[ProcessHub] Hello World | node: :nonode@nohost"

iex> LoggerService.format_message("Test", %{}, prefix: "Module")
"[ProcessHub][Module] Test | node: :nonode@nohost"
Link to this function

info(message, replacements \\ %{}, opts \\ [])

View Source
@spec info(String.t(), map(), keyword()) :: :ok

Logs an info message with optional placeholders and prefix.

Parameters

  • message - The log message with optional @key placeholders
  • replacements - Map of placeholder keys to values (default: %{})
  • opts - Keyword list of options (default: [])
    • :prefix - Optional string to add after [ProcessHub]

Examples

LoggerService.info("System started")
LoggerService.info("Connected to @host", %{"host" => "localhost"})
Link to this function

notice(message, replacements \\ %{}, opts \\ [])

View Source
@spec notice(String.t(), map(), keyword()) :: :ok

Logs a notice message with optional placeholders and prefix.

Parameters

  • message - The log message with optional @key placeholders
  • replacements - Map of placeholder keys to values (default: %{})
  • opts - Keyword list of options (default: [])
    • :prefix - Optional string to add after [ProcessHub]

Examples

LoggerService.notice("Cache cleared")
LoggerService.notice("User @user logged in", %{"user" => "admin"})
Link to this function

replace_placeholders(message, replacements)

View Source
@spec replace_placeholders(String.t(), map()) :: String.t()

Replaces @key placeholders in a message with values from the replacements map.

Values are converted to strings using inspect/1 for non-string values.

Parameters

  • message - The message string with @key placeholders
  • replacements - Map of string keys to replacement values

Examples

iex> LoggerService.replace_placeholders("Hello @name", %{"name" => "World"})
"Hello World"

iex> LoggerService.replace_placeholders("Node @node", %{"node" => :foo@bar})
"Node :foo@bar"
Link to this function

warning(message, replacements \\ %{}, opts \\ [])

View Source
@spec warning(String.t(), map(), keyword()) :: :ok

Logs a warning message with optional placeholders and prefix.

Parameters

  • message - The log message with optional @key placeholders
  • replacements - Map of placeholder keys to values (default: %{})
  • opts - Keyword list of options (default: [])
    • :prefix - Optional string to add after [ProcessHub]

Examples

LoggerService.warning("Connection timeout")
LoggerService.warning("Retrying @count times", %{"count" => 3}, prefix: "Client")