CandleClock.ErrorLogger (candle_clock v1.0.0) View Source

Link to this section Summary

Functions

Formats the given error using Exception.format/3.

Returns if the environment is within a catch or rescue clause.

Formats and logs the given error of the given kind with an optional preceding message.

Logs a formatted error with an optional preceding message.

Like log_error/3, but also puts the givenmessage before the formatted error.

Link to this section Types

Specs

error() :: any()

Specs

kind() :: :error | :exit

Specs

message() :: binary() | [message()]

Link to this section Functions

Link to this macro

format_error(error, kind)

View Source (macro)

Formats the given error using Exception.format/3.

Adds the current stack trace, if available.

Specs

in_catch?(Macro.Env.t()) :: boolean()

Returns if the environment is within a catch or rescue clause.

Use it like this in a macro:

defmacro maybe_get_stacktrace() do
  if in_catch?(__CALLER__) do
    quote do __STACKTRACE__ end
  else
    quote do [] end
  end
end
Link to this macro

log_error(error, log_level \\ :error, metadata \\ [])

View Source (macro)

Formats and logs the given error using Exception.format/3 and Logger.error/1.

Depending on from where this macro is called, it will also include the stacktrace that was recorded with the error in the log message.

error can be anything, special formatting will be done for certain Erlang error atoms or tuples, as well as Elixir exceptions.

log_level (default :error) can be overwritten to log in a different level

metadata optional metadata passed into the Logger

Link to this macro

log_error_raw(message, kind, error, log_level \\ :error, metadata \\ [])

View Source (macro)

Formats and logs the given error of the given kind with an optional preceding message.

Link to this macro

log_exit(error, pid \\ nil, log_level \\ :error, metadata \\ [])

View Source (macro)

Like log_error/3, but is used to log caught exits.

When the pid is given, it will pass {:EXIT, pid} instead of :exit to Exception.format/3.

Link to this function

log_formatted(formatted, message, level \\ :error, metadata \\ [])

View Source

Specs

log_formatted(
  binary(),
  message(),
  level :: Logger.level(),
  metadata :: Logger.metadata()
) :: no_return()

Logs a formatted error with an optional preceding message.

Link to this macro

log_message_and_error(message, error, log_level \\ :error, metadata \\ [])

View Source (macro)

Like log_error/3, but also puts the givenmessage before the formatted error.