nallwhy

nallwhy

How can I disable logging of specific library?

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

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.

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

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
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 record...
New
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 45766 226
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement