From 1b2baf154d20d75a3bcfbf8349add2bc09df9ec3 Mon Sep 17 00:00:00 2001 From: Andrew Dryga Date: Tue, 21 May 2024 17:15:52 -0600 Subject: [PATCH] Remove unused import warnings --- lib/logger_json/formatters/basic.ex | 9 ++++----- lib/logger_json/formatters/datadog.ex | 9 ++++----- lib/logger_json/formatters/elastic.ex | 5 ++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/logger_json/formatters/basic.ex b/lib/logger_json/formatters/basic.ex index 72c5b2d..93bd31d 100644 --- a/lib/logger_json/formatters/basic.ex +++ b/lib/logger_json/formatters/basic.ex @@ -15,6 +15,7 @@ defmodule LoggerJSON.Formatters.Basic do } """ import LoggerJSON.Formatter.{MapBuilder, DateTime, Message, Metadata, RedactorEncoder} + require Jason.Helpers @behaviour LoggerJSON.Formatter @@ -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) ) diff --git a/lib/logger_json/formatters/datadog.ex b/lib/logger_json/formatters/datadog.ex index 588b07d..b1ff774 100644 --- a/lib/logger_json/formatters/datadog.ex +++ b/lib/logger_json/formatters/datadog.ex @@ -42,6 +42,7 @@ defmodule LoggerJSON.Formatters.Datadog do } """ import LoggerJSON.Formatter.{MapBuilder, DateTime, Message, Metadata, Code, RedactorEncoder} + require Jason.Helpers @behaviour LoggerJSON.Formatter @@ -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") @@ -204,7 +203,7 @@ defmodule LoggerJSON.Formatters.Datadog do %{ http: - json_map( + Jason.Helpers.json_map( url: request_url, status_code: conn.status, method: conn.method, @@ -212,7 +211,7 @@ defmodule LoggerJSON.Formatters.Datadog do 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, @@ -220,7 +219,7 @@ defmodule LoggerJSON.Formatters.Datadog do 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 diff --git a/lib/logger_json/formatters/elastic.ex b/lib/logger_json/formatters/elastic.ex index aa1a12e..992a142 100644 --- a/lib/logger_json/formatters/elastic.ex +++ b/lib/logger_json/formatters/elastic.ex @@ -97,6 +97,7 @@ defmodule LoggerJSON.Formatters.Elastic do ``` """ import LoggerJSON.Formatter.{MapBuilder, DateTime, Message, Metadata, RedactorEncoder} + require Jason.Helpers @behaviour LoggerJSON.Formatter @@ -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,