Skip to content

Commit

Permalink
Fixed plug attach docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewDryga committed May 14, 2024
1 parent 3a31b0a commit dddd2a1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/logger_json/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ defmodule LoggerJSON.Plug do
Attaching the telemetry handler to the `MyApp.Repo` events with the `:info` log level:
LoggerJSON.Plug.attach("logger-json-queries, [:my_app, :repo, :query], :info)
# in the endpoint
plug Plug.Telemetry, event_prefix: [:myapp, :plug]
For more details on event and handler naming see
(`Ecto.Repo` documentation)[https://hexdocs.pm/ecto/Ecto.Repo.html#module-telemetry-events].
# in your application.ex
LoggerJSON.Plug.attach("logger-json-requests, [:myapp, :plug, :stop], :info)
To make plug broadcast those events see [`Plug.Telemetry`](https://hexdocs.pm/plug/Plug.Telemetry.html) documentation.
You can also attach to the `[:phoenix, :endpoint, :stop]` event to log request latency from Phoenix endpoints:
LoggerJSON.Plug.attach("logger-json-phoenix-requests, [:phoenix, :endpoint, :stop], :info)
"""
def attach(level) do
:telemetry.attach("logger-json", [:phoenix, :endpoint, :stop], &telemetry_logging_handler/4, level)
def attach(name, event, level) do
:telemetry.attach(name, event, &telemetry_logging_handler/4, level)
end

@doc """
Expand Down

0 comments on commit dddd2a1

Please sign in to comment.