Skip to content

Commit 80dad99

Browse files
scohendoorgan
andauthored
chore: silence spammy log messages (#40)
* chore: Silence spammy log messages For a while now, elixir_sense has been emitting lots of log messages that spammed our logs and made it harder to see what was going on. This PR removes the spam. Now, we remove any log message that has "is already compiled." in it, which handles all of the messages caused by elixir_sense. * fix: remove unused argument --------- Co-authored-by: Dorgan <[email protected]>
1 parent 998414c commit 80dad99

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

apps/engine/lib/engine/engine/bootstrap.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule Engine.Bootstrap do
66
the project's code paths, which are then added to the code paths from the language server. At this
77
point, it's safe to start the project, as we should have all the code present to compile the system.
88
"""
9+
alias Forge.LogFilter
910
alias Forge.Project
1011

1112
require Logger
@@ -66,6 +67,7 @@ defmodule Engine.Bootstrap do
6667
}
6768

6869
:logger.add_handler(handler_name, :logger_std_h, config)
70+
LogFilter.hook_into_logger()
6971
end
7072

7173
defp maybe_change_directory(%Project{} = project) do

apps/expert/lib/expert/application.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule Expert.Application do
44
@moduledoc false
55

66
alias Forge.Document
7+
alias Forge.LogFilter
78

89
use Application
910

@@ -26,6 +27,8 @@ defmodule Expert.Application do
2627
assigns: Expert.Assigns}
2728
]
2829

30+
LogFilter.hook_into_logger()
31+
2932
opts = [strategy: :one_for_one, name: Expert.Supervisor]
3033
Supervisor.start_link(children, opts)
3134
end

apps/forge/lib/forge/log_filter.ex

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
defmodule Forge.LogFilter do
2+
def hook_into_logger() do
3+
:logger.add_primary_filter(:ignore_module_warnings, {&reject_module_warnings/2, []})
4+
end
5+
6+
def reject_module_warnings(log_event, _) do
7+
case log_event do
8+
%{msg: {:report, _}} ->
9+
:ignore
10+
11+
%{msg: {:string, message}} ->
12+
message
13+
|> ensure_binary()
14+
|> action()
15+
16+
%{msg: {format_string, format_data}} ->
17+
format_string
18+
|> :io.format(format_data)
19+
|> ensure_binary()
20+
|> action()
21+
22+
_ ->
23+
:ignore
24+
end
25+
end
26+
27+
defp action(message) do
28+
if message =~ "is already compiled." do
29+
:stop
30+
else
31+
:ignore
32+
end
33+
end
34+
35+
defp ensure_binary(charlist) when is_list(charlist) do
36+
List.to_string(charlist)
37+
end
38+
39+
defp ensure_binary(s) when is_binary(s) do
40+
s
41+
end
42+
end

0 commit comments

Comments
 (0)