Skip to content

Commit 15aa41c

Browse files
committed
add sparrow: false option to Logger calls
1 parent 91a9f2f commit 15aa41c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Sentry client for Elixir based on the new Erlang's [logger](http://erlang.org/do
1414

1515
## Features
1616

17-
* Listen for events in [logger](http://erlang.org/doc/man/logger.html) (instead of deprecated [error_logger](http://erlang.org/doc/man/error_logger.html) or [Logger](https://hexdocs.pm/logger/Logger.html));
17+
* Listen for events in [logger](http://erlang.org/doc/man/logger.html) (instead of deprecated [error_logger](http://erlang.org/doc/man/error_logger.html) and [Logger](https://hexdocs.pm/logger/Logger.html));
1818
* Uses [reducers](/lib/sparrow/event/reducer.ex) to handle formatted erlang reports, like for [Ranch](/lib/sparrow/event/reducers/ranch.ex) (you can use your own reducers);
1919
* Custom [HTTP client](/lib/sparrow/client/behaviour.ex) implementations via configuration (hackney by default);
2020

@@ -54,6 +54,12 @@ Sentry client for Elixir based on the new Erlang's [logger](http://erlang.org/do
5454

5555
After installation and configuration, Sparrow will catch the error reports in your app. But there are some insignificant (for most of us) features that are not documented yet, like custom reducers and HTTP client.
5656

57+
Every `Logger.error` call captured too in Elixir 1.11.x and better, but you can disable this behaviour by providing `sparrow: false` in metadata, like:
58+
59+
```elixir
60+
Logger.error("message", sparrow: false)
61+
```
62+
5763
---
5864

5965
### Contributing

lib/sparrow/catcher.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ defmodule Sparrow.Catcher do
77
Hook required by Erlang `:logger`, should be fast as possible, because it calls on the client process
88
"""
99
@spec log(:logger.log_event(), config :: map) :: any
10+
def log(%{meta: %{sparrow: false}}, _config) do
11+
:skip
12+
end
13+
1014
def log(log, config) do
1115
send(Sparrow.Coordinator, {__MODULE__, log, config})
1216
end

test/integration/logger_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ defmodule Integration.LoggerTest do
2626
assert message == "message"
2727
assert frames == []
2828
end
29+
30+
test "error with sparrow: false option" do
31+
spawn_link(fn ->
32+
Logger.error("message", sparrow: false)
33+
end)
34+
35+
refute_receive %Sparrow.Event{}
36+
end
2937
end
3038
end
3139

0 commit comments

Comments
 (0)