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
debug/3- Debug levelinfo/3- Info levelnotice/3- Notice levelwarning/3- Warning levelerror/3- Error level
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
Logs a debug message with optional placeholders and prefix.
Parameters
message- The log message with optional@keyplaceholdersreplacements- 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")
Logs an error message with optional placeholders and prefix.
Parameters
message- The log message with optional@keyplaceholdersreplacements- 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")
Formats a message with prefix, placeholder replacement, and metadata.
Parameters
message- The log message with optional@keyplaceholdersreplacements- Map of placeholder keys to valuesopts- 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"
Logs an info message with optional placeholders and prefix.
Parameters
message- The log message with optional@keyplaceholdersreplacements- 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"})
Logs a notice message with optional placeholders and prefix.
Parameters
message- The log message with optional@keyplaceholdersreplacements- 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"})
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@keyplaceholdersreplacements- 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"
Logs a warning message with optional placeholders and prefix.
Parameters
message- The log message with optional@keyplaceholdersreplacements- 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")