### Manually start RingLogger backend Source: https://hexdocs.pm/ring_logger Starts the RingLogger backend manually by adding it as a Logger backend and configuring its max_size. This is an alternative to configuring via config.exs. ```elixir Logger.add_backend(RingLogger) Logger.configure_backend(RingLogger, max_size: 1024) ``` -------------------------------- ### Launch RingLogger TUI Source: https://hexdocs.pm/ring_logger Starts the text-based user interface for viewing logs. ```elixir iex> RingLogger.viewer() ``` -------------------------------- ### Configure RingLogger backend in config.exs Source: https://hexdocs.pm/ring_logger Configures the RingLogger backend in config.exs. This removes the default :console backend and sets options like persist_path, persist_seconds, max_size, and custom buffers. The example shows multiple configuration options, including separate buffers for error/warning messages and for all log levels, as well as client options. ```elixir import Config # Add the RingLogger backend. This removes the default :console backend. config :logger, backends: [RingLogger] # Periodically save logs to a file, and load logs on GenServer start from this file config :logger, RingLogger, persist_path: "./myapp.log", persist_seconds: 300 # Save messages to one circular buffer that holds 1024 entries. config :logger, RingLogger, max_size: 1024 # Separate out `:error` and `:warning` messages to their own circular buffer. # All other log messages are stored in the default circular buffer. config :logger, RingLogger, buffers: %{ errors: %{ levels: [:error, :warning], max_size: 1024 } } # Specify circular buffers for all log levels. The default circular buffer won't # be used in this example configuration. config :logger, RingLogger, buffers: %{ low_priority: %{ levels: [:warning, :notice, :info, :debug], max_size: 1024 }, high_priority: %{ levels: [:emergency, :alert, :critical, :error], max_size: 1024 } } # You can also configure `RingLogger.Client` options to be used # with every client by default config :logger, RingLogger, application_levels: %{my_app: :error}, colors: [debug: :yellow], level: :debug ``` -------------------------------- ### Attach to RingLogger and receive logs Source: https://hexdocs.pm/ring_logger Adds the RingLogger backend and attaches to it to start receiving log messages in the console. ```elixir iex> Logger.add_backend(RingLogger) {:ok, #PID<0.199.0>} iex> RingLogger.attach :ok iex> require Logger iex> Logger.info("hello") :ok 14:04:52.516 [info] hello ``` -------------------------------- ### Prioritize Module Over Application Filtering Source: https://hexdocs.pm/ring_logger Demonstrates that module_levels take precedence over application_levels when both are provided. ```elixir iex> RingLogger.attach(application_levels: %{my_app: :info}, module_levels: %{MyApp.Important => :debug}) ``` -------------------------------- ### Combine Module and Global Log Levels Source: https://hexdocs.pm/ring_logger Sets a specific level for a module while applying a different default level for all other modules. ```elixir iex> RingLogger.attach(module_levels: %{MyModule => :debug}, level: :warn) ``` -------------------------------- ### Retrieve raw log entries with RingLogger.get/0 Source: https://hexdocs.pm/ring_logger Returns a list of raw log entries from the RingLogger buffer. Each entry includes the log level, message, timestamp, and metadata such as pid, application, module, function, file, and line. ```elixir iex> RingLogger.get [ debug: {Logger, "8", {{2018, 2, 5}, {17, 44, 7, 675}}, [ pid: #PID<0.139.0>, application: :example, module: Example, function: "log/1", file: "ring_logger/example/lib/example.ex", line: 11 ]}, debug: {Logger, "9", {{2018, 2, 5}, {17, 44, 8, 676}}, [ pid: #PID<0.139.0>, application: :example, module: Example, function: "log/1", file: "ring_logger/example/lib/example.ex", line: 11 ]}, debug: {Logger, "10", {{2018, 2, 5}, {17, 44, 9, 677}}, [ pid: #PID<0.139.0>, application: :example, module: Example, function: "log/1", file: "ring_logger/example/lib/example.ex", line: 11 ]} ] ``` -------------------------------- ### Attach RingLogger with custom formatter and test logging Source: https://hexdocs.pm/ring_logger Attaches RingLogger with the CustomFormatter and metadata for file and line, then logs a test message. The output shows the formatted message with the source location. ```elixir iex> RingLogger.attach(format: {CustomFormatter, :format}, metadata: [:file, :line]) :ok iex> require Logger Logger iex> Logger.info("Important message!") :ok Important message! iex:4 ``` -------------------------------- ### Filter Application Log Levels Source: https://hexdocs.pm/ring_logger Uses the :application_levels option to set a log level for all modules within a specific OTP application. ```elixir iex> RingLogger.attach(application_levels: %{my_app: :info}) ``` -------------------------------- ### View recent log entries with RingLogger.tail Source: https://hexdocs.pm/ring_logger Retrieves and displays the most recent log entries stored in the buffer. ```elixir iex> RingLogger.tail 14:04:52.516 [info] hello 14:11:54.397 [info] Hello logger, how are you? 14:12:09.180 [info] It's a nice day. Wouldn't you say? :ok ``` -------------------------------- ### Poll log messages with RingLogger.next Source: https://hexdocs.pm/ring_logger Detaches from real-time streaming and uses the next function to manually retrieve and print accumulated log messages. ```elixir iex> RingLogger.detach :ok iex> Logger.info("Hello logger, how are you?") :ok iex> Logger.info("It's a nice day. Wouldn't you say?") :ok iex> RingLogger.next 14:04:52.516 [info] hello 14:11:54.397 [info] Hello logger, how are you? 14:12:09.180 [info] It's a nice day. Wouldn't you say? :ok iex> RingLogger.next :ok ``` -------------------------------- ### Add ring_logger dependency in mix.exs Source: https://hexdocs.pm/ring_logger Adds the ring_logger package to the project's dependencies in mix.exs. The version specified is "~> 0.11". ```elixir def deps do [{:ring_logger, "~> 0.11"}] end ``` -------------------------------- ### Filter logs with RingLogger.grep Source: https://hexdocs.pm/ring_logger Filters the log buffer using a regular expression to find specific entries. ```elixir iex> RingLogger.grep(~r/[Nn]eedle/) 16:55:41.614 [info] Needle in a haystack ``` -------------------------------- ### Custom formatter module for RingLogger Source: https://hexdocs.pm/ring_logger Defines a CustomFormatter module that formats log messages with file and line metadata. The format/4 function rescues exceptions and falls back to the raw message. ```elixir defmodule CustomFormatter do def format(_level, message, _timestamp, metadata) do "#{message} #{metadata[:file]}:#{metadata[:line]}\n" rescue _ -> message end end ``` -------------------------------- ### Save RingLogger log buffer to a file Source: https://hexdocs.pm/ring_logger Saves the current log buffer to /tmp/log.txt using RingLogger.save/1. Log messages are formatted the same way as RingLogger console output. ```elixir iex> RingLogger.save("/tmp/log.txt") :ok ``` -------------------------------- ### Remove console backend in IEx Source: https://hexdocs.pm/ring_logger Disables the default console logger to prevent duplicate log messages in the IEx session. ```elixir iex> Logger.remove_backend(:console) :ok ``` -------------------------------- ### Filter Module Log Levels Source: https://hexdocs.pm/ring_logger Uses the :module_levels option to set specific log levels for modules, such as ignoring debug messages for MyModule. ```elixir iex> RingLogger.attach(module_levels: %{MyModule => :info}) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.