View Source NLdoc.Logging.Logger (NLdoc.Logging v1.0.1)

The Logger module provides a simple logging interface for the NLdoc applications. It basically just aliases Logger, but also adds some metadata to each log message.

Additionally, it supports the following metadata keys:

  • error: An exception that occurred in the application. This will be forwarded to Logger as crash_reason along with a stack trace of where the log method was called from.

Configuration

Configure in config/config.exs the following:

# ...

config :logger, :default_handler,
  formatter: {LoggerJSON.Formatters.Elastic, metadata: {:all_except, [:application]}}

config :logger, :console,
  metadata: [
    :error,
    :labels,
    :"url.path",
    :"event.action",
    # ...
    :"service.name",
    :"service.version",
    :"service.environment",
    # ...
    :"trace.id"
    # ... etc, to your own needs.
  ]

  # ...

Summary

Types

stacktrace()

@type stacktrace() :: [{Module, atom(), integer(), file: charlist(), line: integer()}]

Functions

alert(message, metadata \\ [])

@spec alert(String.t() | keyword() | map(), keyword() | nil) :: :ok

critical(message, metadata \\ [])

@spec critical(String.t() | keyword() | map(), keyword() | nil) :: :ok

debug(message, metadata \\ [])

@spec debug(String.t() | keyword() | map(), keyword() | nil) :: :ok

emergency(message, metadata \\ [])

@spec emergency(String.t() | keyword() | map(), keyword() | nil) :: :ok

error(message, metadata \\ [])

@spec error(String.t() | keyword() | map(), keyword() | nil) :: :ok

flush()

@spec flush() :: :ok

get_stacktrace()

@spec get_stacktrace() :: stacktrace()

Returns the stacktrace of the calling function.

info(message, metadata \\ [])

@spec info(String.t() | keyword() | map(), keyword() | nil) :: :ok

init(name, version, environment)

@spec init(name :: String.t(), version :: String.t(), environment :: String.t()) ::
  :ok

notice(message, metadata \\ [])

@spec notice(String.t() | keyword() | map(), keyword() | nil) :: :ok

warning(message, metadata \\ [])

@spec warning(String.t() | keyword() | map(), keyword() | nil) :: :ok