### Initialize a backend Source: https://hexdocs.pm/logger_backends/LoggerBackends.html Example of adding a backend which triggers the init/1 callback in the specified module. ```elixir LoggerBackends.add(MyBackend) ``` -------------------------------- ### Handle backend configuration Source: https://hexdocs.pm/logger_backends/LoggerBackends.html Example of handling the :configure event to update backend state. ```elixir {:configure, options} ``` ```elixir def handle_call({:configure, options}, state) do new_state = reconfigure_state(state, options) {:ok, :ok, new_state} end ``` -------------------------------- ### Add a backend Source: https://hexdocs.pm/logger_backends/index.html Adds a new backend and returns the supervisor start result. ```elixir @spec add( backend(), keyword() ) :: Supervisor.on_start_child() ``` ```elixir LoggerBackends.add(MyBackend) ``` -------------------------------- ### Configure Console Backend in config.exs Source: https://hexdocs.pm/logger_backends/LoggerBackends.Console.html Example configuration for the console logger backend within an Elixir project's configuration file. ```elixir config :logger, LoggerBackends.Console, format: "\n$time $metadata[$level] $message\n", metadata: [:user_id] ``` -------------------------------- ### Add a custom backend in Application.start/2 Source: https://hexdocs.pm/logger_backends/index.html Register a custom backend during the application startup process. ```elixir @impl true def start(_type, _args) do LoggerBackends.add(MyCustomBackend) # ... end ``` -------------------------------- ### configure(options) Source: https://hexdocs.pm/logger_backends/index.html Applies runtime configuration to all backends. ```APIDOC ## configure(options) ### Description Applies runtime configuration to all backends. ### Signature `configure(options) :: :ok` ``` -------------------------------- ### configure(options) Source: https://hexdocs.pm/logger_backends/index.html Applies runtime configuration to all backends. ```APIDOC ## configure(options) ### Description Applies runtime configuration to all backends. ### Signature `configure(options :: keyword()) :: :ok` ``` -------------------------------- ### configure(options) Source: https://hexdocs.pm/logger_backends/LoggerBackends.html Applies runtime configuration to all backends. ```APIDOC ## configure(options) ### Description Applies runtime configuration to all backends. ### Parameters - **options** (keyword()) - Required - The configuration options to apply to all backends. ``` -------------------------------- ### configure(backend, options) Source: https://hexdocs.pm/logger_backends/index.html Configures a specific given backend. ```APIDOC ## configure(backend, options) ### Description Configures a given backend. ### Signature `configure(backend(), options) :: :ok | {:error, term()}` ``` -------------------------------- ### configure(backend, options) Source: https://hexdocs.pm/logger_backends/LoggerBackends.html Configures a specific backend. ```APIDOC ## configure(backend, options) ### Description Applies runtime configuration to a specific backend. ### Parameters - **backend** (backend()) - Required - The backend to configure. - **options** (keyword()) - Required - The configuration options to apply. ``` -------------------------------- ### configure(backend, options) Source: https://hexdocs.pm/logger_backends/index.html Configures a specific backend. ```APIDOC ## configure(backend, options) ### Description Configures a given backend. ### Signature `configure(backend :: backend(), options :: keyword()) :: term()` ``` -------------------------------- ### Configure all backends Source: https://hexdocs.pm/logger_backends/index.html Applies runtime configuration to all registered backends. ```elixir @spec configure(keyword()) :: :ok ``` -------------------------------- ### add(backend, opts \ []) Source: https://hexdocs.pm/logger_backends/LoggerBackends.html Adds a new backend to the logger system. This function triggers the init/1 callback of the specified backend. ```APIDOC ## add(backend, opts \ []) ### Description Adds a new backend to the logger system. Adding a backend calls the init/1 function in that backend with the name of the backend as its argument. ### Parameters - **backend** (backend()) - Required - The logger handler to add. - **opts** (keyword()) - Optional - Configuration options. Supported option: :flush (when true, guarantees all messages currently sent to Logger are processed before the backend is added). ### Returns - **{:ok, pid}** - Returned if the backend's init/1 callback returns {:ok, _} or {:error, :ignore}. - **{:error, {reason, info}}** - Returned if the handler returns {:error, reason} from init/1. ``` -------------------------------- ### Configure a custom backend Source: https://hexdocs.pm/logger_backends/index.html Define configuration parameters for a custom backend within the application's configuration files. ```elixir config :logger, MyCustomBackend, some_config: ... ``` -------------------------------- ### Configure a specific backend Source: https://hexdocs.pm/logger_backends/index.html Applies configuration settings to a single specified backend. ```elixir @spec configure( backend(), keyword() ) :: term() ``` -------------------------------- ### Handle backend configuration calls Source: https://hexdocs.pm/logger_backends/index.html Implement this handle_call clause to process configuration updates sent via configure_backend/2. ```elixir def handle_call({:configure, options}, state) do new_state = reconfigure_state(state, options) {:ok, :ok, new_state} end ``` -------------------------------- ### build(event) Source: https://hexdocs.pm/logger_backends_json/Logger.Backends.JSON.Event.html Transforms a log event into a map structure suitable for JSON output. ```APIDOC ## build(event) ### Description Builds a map from the provided event message, which is subsequently used as input for JSON serialization. ### Parameters - **event** (struct) - Required - A Logger.Backends.JSON.Event struct. ### Returns - **map** - A map representation of the log event. ``` -------------------------------- ### Define backend type Source: https://hexdocs.pm/logger_backends/index.html Represents a logger handler as a gen_event handler. ```elixir @type backend() :: :gen_event.handler() ``` -------------------------------- ### LoggerBackends.Console Configuration Source: https://hexdocs.pm/logger_backends/LoggerBackends.Console.html Configuration options for the LoggerBackends.Console backend in an Elixir application. ```APIDOC ## Configuration Options ### Description The `LoggerBackends.Console` backend can be configured in your `config/config.exs` file to customize how logs are printed to the console. ### Options - **:level** (atom) - The minimum level to be logged by this backend. - **:format** (string | {module, function}) - The format message used to print logs. Defaults to: `"\n$time $metadata[$level] $message\n"`. - **:metadata** (list | :all) - The metadata to be printed. Defaults to an empty list. - **:colors** (keyword list) - Coloring options for different log levels. - **:device** (atom) - The device to log messages to. Defaults to `:user`. - **:max_buffer** (integer) - Maximum events to buffer while waiting for IO confirmation. Defaults to 32. ### Example ```elixir config :logger, LoggerBackends.Console, format: "\n$time $metadata[$level] $message\n", metadata: [:user_id] ``` ``` -------------------------------- ### Add a backend Source: https://hexdocs.pm/logger_backends/LoggerBackends.html Adds a new backend and specifies the return type for the operation. ```elixir @spec add( backend(), keyword() ) :: Supervisor.on_start_child() ``` -------------------------------- ### remove(backend, opts) Source: https://hexdocs.pm/logger_backends/index.html Removes a backend with optional flush configuration. ```APIDOC ## remove(backend, opts \\ []) ### Description Removes a backend. ### Signature `remove(backend :: backend(), opts :: keyword()) :: :ok | {:error, term()} ### Parameters - **flush** (boolean) - Optional - When true, guarantees all messages currently sent to Logger are processed before the backend is removed. ``` -------------------------------- ### remove(backend, opts \ []) Source: https://hexdocs.pm/logger_backends/LoggerBackends.html Removes a backend from the logger system. ```APIDOC ## remove(backend, opts \ []) ### Description Removes a backend from the logger system. ### Parameters - **backend** (backend()) - Required - The backend to remove. - **opts** (keyword()) - Optional - Configuration options. ``` -------------------------------- ### remove(backend, opts \ []) Source: https://hexdocs.pm/logger_backends/index.html Removes a specified backend. ```APIDOC ## remove(backend, opts \ []) ### Description Removes a backend. ### Signature `remove(backend(), keyword()) :: :ok | {:error, term()}` ``` -------------------------------- ### allow?(event) Source: https://hexdocs.pm/logger_backends_json/Logger.Backends.JSON.Event.html Determines whether a log event should be processed based on custom logic. ```APIDOC ## allow?(event) ### Description Decides whether to proceed with evaluating the log entry. This acts as an additional layer of filtering beyond the standard log level configuration. ### Parameters - **event** (struct) - Required - A Logger.Backends.JSON.Event struct. ### Returns - **boolean** - Returns true if the event should be processed, false otherwise. ``` -------------------------------- ### Remove a backend Source: https://hexdocs.pm/logger_backends/index.html Removes a backend from the logger. Use the :flush option to ensure pending messages are processed before removal. ```elixir @spec remove( backend(), keyword() ) :: :ok | {:error, term()} ``` -------------------------------- ### remove(backend, opts) Source: https://hexdocs.pm/logger_backends/LoggerBackends.html Removes a specified backend from the logger. ```APIDOC ## remove(backend, opts \\ []) ### Description Removes a backend. ### Signature `remove(backend :: backend(), opts :: keyword()) :: :ok | {:error, term()} ### Parameters - **backend** (backend()) - Required - The backend to remove. - **opts** (keyword()) - Optional - Options for removal. - **flush** (boolean) - When true, guarantees all messages currently sent to Logger are processed before the backend is removed. ``` -------------------------------- ### encode(object) Source: https://hexdocs.pm/logger_backends_json/Logger.Backends.JSON.DummyEncoder.html Encodes a given object into a JSON format suitable for logging. ```APIDOC ## encode(object) ### Description Encodes the provided object into a JSON representation for use in logging backends. ### Parameters - **object** (any) - Required - The data structure to be encoded into JSON. ``` -------------------------------- ### Ignore remote group leader events in custom backend Source: https://hexdocs.pm/logger_backends/index.html Use this pattern in handle_event to filter out messages originating from different nodes. ```elixir def handle_event({_level, gl, {Logger, _, _, _}}, state) when node(gl) != node() do {:ok, state} end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.