Skip to content

Commit 3d16230

Browse files
committed
Improve logging documentation
1 parent 80e32f0 commit 3d16230

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/sentry/logger_handler.ex

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@ defmodule Sentry.LoggerHandler do
152152
153153
#{NimbleOptions.docs(@options_schema)}
154154
155+
## Examples
156+
157+
To log all messages with level `:error` and above to Sentry, set `:capture_log_messages`
158+
to `true`:
159+
160+
config :my_app, :logger, [
161+
{:handler, :my_sentry_handler, Sentry.LoggerHandler, %{
162+
config: %{metadata: [:file, :line], capture_log_messages: true, level: :error}
163+
}}
164+
]
165+
166+
Now, logs like this will be reported as messages to Sentry:
167+
168+
Logger.error("Something went wrong")
169+
170+
If you want to customize options for the reported message, use the `:sentry` metadata
171+
key in the `Logger` call. For example, to add a tag to the Sentry event:
172+
173+
Logger.error("Something went wrong", sentry: [tags: %{my_tag: "my_value"}])
174+
175+
Sentry context (in `:sentry`) is also read from the logger metadata, so you can configure
176+
it for a whole process (with `Logger.metadata/1`). Last but not least, context is also read
177+
from the ancestor chain of the process (`:"$callers"`), so if you set `:sentry` context
178+
in a process and then spawn something like a task or a GenServer from that process,
179+
the context will be included in the reported messages.
155180
"""
156181

157182
@moduledoc since: "9.0.0"

0 commit comments

Comments
 (0)