ring_logger v0.4.1 RingLogger

This is an in-memory ring buffer backend for the Elixir Logger.

Install it by adding it to your config.exs:

use Mix.Config

# Add the RingLogger backend. This removes the
# default :console backend.
config :logger, backends: [RingLogger]

# Set the number of messages to hold in the circular buffer
config :logger, RingLogger, max_size: 100

Or add manually:

Logger.add_backend(RingLogger)
Logger.configure(RingLogger, max_size: 100)

Once added as a backend, you have two options depending on whether you’re accessing the RingLogger via the IEx prompt or via code. If you’re at the IEx prompt, use the helper methods in here like attach, detach, tail, grep, etc. They’ll automate a few things behind the scenes. If you’re writing a program that needs to get log messages, use get or start_link a RingLogger.Client and call its methods directly.

Link to this section Summary

Types

Option values used by client-side functions like attach and tail

A tuple holding a raw, unformatted log entry

Option values used by the ring logger

Functions

Attach the current IEx session to the logger. It will start printing log messages

Callback implementation for c::gen_event.code_change/3

Update the logger configuration

Detach the current IEx session from the logger

Helper method for formatting log messages per the current client’s configuration

Get all log messages at the specified index and later

Run a regular expression on each entry in the log and print out the matchers

Callback implementation for c::gen_event.handle_call/2

Callback implementation for c::gen_event.handle_event/2

Callback implementation for c::gen_event.handle_info/2

Callback implementation for c::gen_event.init/1

Reset the index into the log for tail/1 to the oldest entry

Tail the messages in the log

Callback implementation for c::gen_event.terminate/2

Link to this section Types

Link to this type client_option()
client_option() ::
  {:io, term()}
  | {:color, term()}
  | {:metadata, Logger.metadata()}
  | {:format, String.t()}
  | {:level, Logger.level()}

Option values used by client-side functions like attach and tail

A tuple holding a raw, unformatted log entry

Link to this type server_option()
server_option() :: {:max_size, pos_integer()}

Option values used by the ring logger

Link to this section Functions

Link to this function attach(opts \\ [])
attach([client_option()]) :: :ok

Attach the current IEx session to the logger. It will start printing log messages.

Options include:

  • :io - Defaults to :stdio
  • :colors -
  • :metadata - A KV list of additional metadata
  • :format - A custom format string
  • :level - The minimum log level to report.
Link to this function code_change(old_vsn, state, extra)

Callback implementation for c::gen_event.code_change/3.

Link to this function configure(opts)
configure([server_option()]) :: :ok

Update the logger configuration.

Options include:

  • :max_size - the max number of log messages to store at a time
Link to this function detach()
detach() :: :ok

Detach the current IEx session from the logger.

Link to this function format(message)
format(entry()) :: :ok

Helper method for formatting log messages per the current client’s configuration.

Link to this function get(index \\ 0)
get(non_neg_integer()) :: [entry()]

Get all log messages at the specified index and later.

Link to this function grep(regex, opts \\ [])
grep(Regex.t(), [client_option()]) :: :ok | {:error, term()}

Run a regular expression on each entry in the log and print out the matchers.

For example:

iex> RingLogger.grep(~r/something/) :ok

Link to this function handle_call(arg, state)

Callback implementation for c::gen_event.handle_call/2.

Link to this function handle_event(arg1, state)

Callback implementation for c::gen_event.handle_event/2.

Link to this function handle_info(_, state)

Callback implementation for c::gen_event.handle_info/2.

Link to this function init(arg1)
init(module()) :: {:ok, term()} | {:error, term()}
init({module(), list()}) :: {:ok, term()} | {:error, term()}

Callback implementation for c::gen_event.init/1.

Link to this function reset(opts \\ [])
reset([client_option()]) :: :ok | {:error, term()}

Reset the index into the log for tail/1 to the oldest entry.

Link to this function tail(opts \\ [])
tail([client_option()]) :: :ok | {:error, term()}

Tail the messages in the log.

Link to this function terminate(reason, state)

Callback implementation for c::gen_event.terminate/2.