nallwhy

nallwhy

How can I disable logging of specific library?

I’m using GitHub - larskrantz/logger_papertrail_backend: A Papertrail backend for Elixir Logger · GitHub.

From Elixir v1.15.0, it shows warnings like below.

warning: the log level :warn is deprecated, use :warning instead
  (logger 1.15.0) lib/logger.ex:1137: Logger.elixir_level_to_erlang_level/1
  (logger 1.15.0) lib/logger.ex:591: Logger.compare_levels/2
  (logger_papertrail_backend 1.1.0) lib/logger_papertrail_backend/logger.ex:60: LoggerPapertrailBackend.Logger.meet_level?/2
  (logger_papertrail_backend 1.1.0) lib/logger_papertrail_backend/logger.ex:33: LoggerPapertrailBackend.Logger.handle_event/2
  (stdlib 5.0.1) gen_event.erl:802: :gen_event.server_update/4
  (stdlib 5.0.1) gen_event.erl:784: :gen_event.server_notify/4
  (stdlib 5.0.1) gen_event.erl:786: :gen_event.server_notify/4
  (stdlib 5.0.1) gen_event.erl:526: :gen_event.handle_msg/6
  (stdlib 5.0.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

Logger send :warn to logger backends instead of :warning.

This is reported as “warn” in Elixir’s logger backends for backwards compatibility reasons.

https://github.com/elixir-lang/elixir/blob/v1.14.4/lib/logger/lib/logger.ex#L956

logger_papertrail_backend uses Logger.compare_level/2, so it inputs :warn to Logger.compare_level/2.

I want to disable that warning from logger_papertrail_backend.

How can I do that?

Marked As Solved

christhekeele

christhekeele

Per the Logger docs:

If you want to purge all log calls from an application named :foo and only keep errors from Bar.foo/3, you can set up two different matches:

config :logger,
  compile_time_purge_matching: [
    [application: :foo],
    [module: Bar, function: "foo/3", level_lower_than: :error]
  ]

So I assume for your purposes you could write something like:

config :logger, compile_time_purge_matching: [
  [application: :logger_papertrail_backend, level_lower_than: :error
]

Also Liked

suddengunter

suddengunter

Good idea, but no, I see ExMQTT logs:
they are all prefixed with [ExMQTT]

[debug] [ExMQTT] Connecting to localhost:1883
....
[debug] [ExMQTT] Connected #PID<0.711.0>

Another thing to be aware is that you need recompile the deps after setting up the config.

Yeah, I’ve tried it:

rm -rf _build
rm -rf deps
mix deps.get
mix deps.compile
mix phx.server

I’m starting to think maybe there is something specific to running the app with mix phx.server that is breaking this for me

UPD:
I fixed it with this:

# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"

Logger.put_module_level(ExMQTT, :error)
Logger.put_module_level(:emqtt, :error)

I don’t really like that those put_module_level are not part of config :logger section, but I was not able to figure out how to do it otherwise (and compile_time_purge_matching also did not work, not sure why - don’t really care in this case)

nallwhy

nallwhy

Thank you!

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48475 226
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42158 114
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New

We're in Beta

About us Mission Statement