Skip to content

Commit

Permalink
Remove unused import warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewDryga committed May 21, 2024
1 parent 1a72c79 commit 1b2baf1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
9 changes: 4 additions & 5 deletions lib/logger_json/formatters/basic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule LoggerJSON.Formatters.Basic do
}
"""
import LoggerJSON.Formatter.{MapBuilder, DateTime, Message, Metadata, RedactorEncoder}
require Jason.Helpers

@behaviour LoggerJSON.Formatter

Expand Down Expand Up @@ -71,19 +72,17 @@ defmodule LoggerJSON.Formatters.Basic do
end

if Code.ensure_loaded?(Plug.Conn) do
import Jason.Helpers, only: [json_map: 1]

defp format_http_request(%{conn: %Plug.Conn{} = conn}) do
json_map(
Jason.Helpers.json_map(
connection:
json_map(
Jason.Helpers.json_map(
protocol: Plug.Conn.get_http_protocol(conn),
method: conn.method,
path: conn.request_path,
status: conn.status
),
client:
json_map(
Jason.Helpers.json_map(
user_agent: LoggerJSON.Formatter.Plug.get_header(conn, "user-agent"),
ip: LoggerJSON.Formatter.Plug.remote_ip(conn)
)
Expand Down
9 changes: 4 additions & 5 deletions lib/logger_json/formatters/datadog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ defmodule LoggerJSON.Formatters.Datadog do
}
"""
import LoggerJSON.Formatter.{MapBuilder, DateTime, Message, Metadata, Code, RedactorEncoder}
require Jason.Helpers

@behaviour LoggerJSON.Formatter

Expand Down Expand Up @@ -194,8 +195,6 @@ defmodule LoggerJSON.Formatters.Datadog do
defp safe_chardata_to_string(other), do: other

if Code.ensure_loaded?(Plug.Conn) do
import Jason.Helpers, only: [json_map: 1]

defp format_http_request(%{conn: %Plug.Conn{} = conn} = meta) do
request_url = Plug.Conn.request_url(conn)
user_agent = LoggerJSON.Formatter.Plug.get_header(conn, "user-agent")
Expand All @@ -204,23 +203,23 @@ defmodule LoggerJSON.Formatters.Datadog do

%{
http:
json_map(
Jason.Helpers.json_map(
url: request_url,
status_code: conn.status,
method: conn.method,
referer: referer,
request_id: meta[:request_id],
useragent: user_agent,
url_details:
json_map(
Jason.Helpers.json_map(
host: conn.host,
port: conn.port,
path: conn.request_path,
queryString: conn.query_string,
scheme: conn.scheme
)
),
network: json_map(client: json_map(ip: remote_ip))
network: Jason.Helpers.json_map(client: Jason.Helpers.json_map(ip: remote_ip))
}
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/logger_json/formatters/elastic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ defmodule LoggerJSON.Formatters.Elastic do
```
"""
import LoggerJSON.Formatter.{MapBuilder, DateTime, Message, Metadata, RedactorEncoder}
require Jason.Helpers

@behaviour LoggerJSON.Formatter

Expand Down Expand Up @@ -222,15 +223,13 @@ defmodule LoggerJSON.Formatters.Elastic do
defp format_logger_fields(_meta), do: nil

if Code.ensure_loaded?(Plug.Conn) do
import Jason.Helpers, only: [json_map: 1]

# See the formats for the following fields in ECS:
# - client.ip: https://www.elastic.co/guide/en/ecs/8.11/ecs-client.html
# - http.*: https://www.elastic.co/guide/en/ecs/8.11/ecs-http.html
# - url.path: https://www.elastic.co/guide/en/ecs/8.11/ecs-url.html
# - user_agent.original: https://www.elastic.co/guide/en/ecs/8.11/ecs-user_agent.html
defp format_http_request(%{conn: %Plug.Conn{} = conn}) do
json_map(
Jason.Helpers.json_map(
"client.ip": LoggerJSON.Formatter.Plug.remote_ip(conn),
"http.version": Plug.Conn.get_http_protocol(conn),
"http.request.method": conn.method,
Expand Down

0 comments on commit 1b2baf1

Please sign in to comment.