Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add @impl to logger interceptor callback #231

Merged
merged 6 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/grpc/logger/client.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
defmodule GRPC.Logger.Client do
require Logger

@moduledoc """
Print log around client rpc calls, like

Expand All @@ -13,13 +11,19 @@ defmodule GRPC.Logger.Client do
{:ok, channel} = GRPC.Stub.connect("localhost:50051", interceptors: [{GRPC.Logger.Client, level: :info}])
"""

require Logger

@behaviour GRPC.ClientInterceptor

@impl true
def init(opts) do
level = Keyword.get(opts, :level) || :info
[level: level]
end

@impl true
def call(%{grpc_type: grpc_type} = stream, req, next, opts) do
level = opts[:level]
level = Keyword.fetch!(opts, :level)

if Logger.compare_levels(level, Logger.level()) != :lt do
Logger.log(level, fn ->
Expand Down
6 changes: 5 additions & 1 deletion lib/grpc/logger/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ defmodule GRPC.Logger.Server do
intercept GRPC.Logger.Server, level: :info
end
"""

require Logger

@behaviour GRPC.ServerInterceptor

@impl true
def init(opts) do
level = Keyword.get(opts, :level) || :info
level = opts[:level] || :info
polvalente marked this conversation as resolved.
Show resolved Hide resolved
[level: level]
end

@impl true
def call(req, stream, next, opts) do
level = Keyword.fetch!(opts, :level)

Expand Down