ring_logger v0.7.0 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: 1024
Or add manually:
Logger.add_backend(RingLogger)
Logger.configure(RingLogger, max_size: 1024)
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, next,
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
Callback function for printing/paging tail, grep, and next output
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 n log messages starting at the specified index.
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.
Print the next messages in the log.
Reset the index into the log for tail/1 to the oldest entry.
Save the contents of the log to the specified path
Print the last n messages in the log.
Callback implementation for c::gen_event.terminate/2.
Link to this section Types
client_option()
client_option() ::
{:io, term()}
| {:pager, pager_fun()}
| {:color, term()}
| {:metadata, Logger.metadata()}
| {:format, String.t() | custom_formatter()}
| {:level, Logger.level()}
| {:module_levels, map()}
client_option() ::
{:io, term()}
| {:pager, pager_fun()}
| {:color, term()}
| {:metadata, Logger.metadata()}
| {:format, String.t() | custom_formatter()}
| {:level, Logger.level()}
| {:module_levels, map()}
Option values used by client-side functions like attach and tail
entry()
entry() ::
{module(), Logger.level(), Logger.message(), Logger.Formatter.time(),
Logger.metadata()}
entry() ::
{module(), Logger.level(), Logger.message(), Logger.Formatter.time(),
Logger.metadata()}
A tuple holding a raw, unformatted log entry
pager_fun()
Callback function for printing/paging tail, grep, and next output
server_option()
server_option() :: {:max_size, pos_integer()}
server_option() :: {:max_size, pos_integer()}
Option values used by the ring logger
Link to this section Functions
attach(opts \\ [])
attach([client_option()]) :: :ok
attach([client_option()]) :: :ok
Attach the current IEx session to the logger. It will start printing log messages.
Options include:
:io- output location when printing. Defaults to:stdio:colors- a keyword list of coloring options:metadata- a keyword list of additional metadata:format- the format message used to print logs:level- the minimum log level to report by this backend. Note that the:loggerapplication's:levelsetting filters log messages prior toRingLogger.:module_levels- a map of log level overrides per module. For example, %{MyModule => :error, MyOtherModule => :none}
code_change(old_vsn, state, extra)
Callback implementation for c::gen_event.code_change/3.
configure(opts)
configure([server_option()]) :: :ok
configure([server_option()]) :: :ok
Update the logger configuration.
Options include:
:max_size- the max number of log messages to store at a time
detach()
detach() :: :ok
detach() :: :ok
Detach the current IEx session from the logger.
format(message)
format(entry()) :: :ok
format(entry()) :: :ok
Helper method for formatting log messages per the current client's configuration.
get(index \\ 0, n \\ 0)
get(non_neg_integer(), non_neg_integer()) :: [entry()]
get(non_neg_integer(), non_neg_integer()) :: [entry()]
Get n log messages starting at the specified index.
Set n to 0 to get entries to the end
grep(regex_or_string, opts \\ [])
grep(Regex.t() | String.t(), [client_option()]) :: :ok | {:error, term()}
grep(Regex.t() | String.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
Options include:
- Options from
attach/1 :pager- a function for printing log messages to the console. Defaults toIO.binwrite/2.
handle_call(arg, state)
Callback implementation for c::gen_event.handle_call/2.
handle_event(arg1, state)
Callback implementation for c::gen_event.handle_event/2.
handle_info(_, state)
Callback implementation for c::gen_event.handle_info/2.
init(arg1)
Callback implementation for c::gen_event.init/1.
next(opts \\ [])
next([client_option()]) :: :ok | {:error, term()}
next([client_option()]) :: :ok | {:error, term()}
Print the next messages in the log.
Options include:
- Options from
attach/1 :pager- a function for printing log messages to the console. Defaults toIO.binwrite/2.
reset(opts \\ [])
reset([client_option()]) :: :ok | {:error, term()}
reset([client_option()]) :: :ok | {:error, term()}
Reset the index into the log for tail/1 to the oldest entry.
save(path)
Save the contents of the log to the specified path
The file is overwritten if it already exists. Log message formatting is done similarly to other RingLogger calls.
tail()
Print the last n messages in the log.
Options include:
- Options from
attach/1 :pager- a function for printing log messages to the console. Defaults toIO.binwrite/2.
tail(opts)
tail(n, opts)
tail(non_neg_integer(), [client_option()]) :: :ok | {:error, term()}
tail(non_neg_integer(), [client_option()]) :: :ok | {:error, term()}
terminate(reason, state)
Callback implementation for c::gen_event.terminate/2.