Created
March 21, 2025 14:23
-
-
Save xtreme-sameer-vohra/4dc57cd089ac85937d4c93e0c6adb887 to your computer and use it in GitHub Desktop.
Elixir custom logging filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add line to application | |
:logger.add_primary_filter(:noise_filter, {&DevelopmentLogger.filter/2, []}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule DevelopmentLogger do | |
@moduledoc """ | |
For DEVELOPMENT use ONLY !!! | |
Filter out logs by module | |
Reference - https://write.as/yuriploc/elixir-logger-and-erlang-filters | |
""" | |
IO.puts("For DEVELOPMENT use ONLY !!!") | |
@noisy_modules [Ecto.Adapters.SQL, Phoenix.Logger] | |
@spec filter(map(), keyword()) :: :stop | :ignore | map() | |
def filter(%{meta: %{mfa: {module, _, _}}} = log_event, _opts) when module in @noisy_modules do | |
# IO.inspect(module, label: "Noisy Module:") | |
:stop | |
end | |
@spec filter(map(), keyword()) :: :stop | :ignore | map() | |
def filter(%{meta: %{mfa: {module, _, _}}} = log_event, _opts) do | |
# IO.inspect(module, label: "Unfiltered Module:") | |
:ignore | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use during development to reduce logs to specific modules under development.
Add the line to application.ex -> start function