Skip to content

Commit

Permalink
Remove the logfmt lib
Browse files Browse the repository at this point in the history
  • Loading branch information
joshk committed Oct 1, 2024
1 parent 1165390 commit 50a99d0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
27 changes: 8 additions & 19 deletions lib/nerves_hub/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,14 @@ defmodule NervesHub.Logger do
# Phoenix request logging

@doc false
def log_event([:phoenix, :endpoint, :stop], %{duration: duration}, %{conn: conn} = metadata, _) do
case log_level(metadata[:options][:log], conn) do
false ->
:ok

level ->
Logger.log(level, fn ->
Logfmt.encode(
duration: duration(duration),
method: conn.method,
path: request_path(conn),
status: conn.status,
remote_ip: formatted_ip(conn)
)
end)
end
def log_event([:phoenix, :endpoint, :stop], %{duration: duration}, %{conn: conn}, _) do
Logger.info("Request completed", %{
duration: duration(duration),
method: conn.method,
path: request_path(conn),
status: conn.status,
remote_ip: formatted_ip(conn)
})
end

def log_event([:nerves_hub, :devices, :connect], _, metadata, _) do
Expand Down Expand Up @@ -114,7 +106,4 @@ defmodule NervesHub.Logger do
|> to_string()
end
end

defp log_level(nil, _conn), do: :info
defp log_level(level, _conn) when is_atom(level), do: level
end
2 changes: 1 addition & 1 deletion lib/nerves_hub/logger_formatter.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule NervesHub.LoggerFormatter do
@metadata_ignore_list [:line, :file, :domain, :application, :pid, :mfa]
@pattern Logger.Formatter.compile("$time [$level] $metadata$message\n")
@pattern Logger.Formatter.compile("$time [$level] msg=\"$message\" $metadata\n")

def format(level, message, timestamp, metadata) do
metadata = Keyword.drop(metadata, ignore_list())
Expand Down
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ defmodule NervesHub.MixProject do
{:hlclock, "~> 1.0"},
{:jason, "~> 1.2", override: true},
{:libcluster_postgres, "~> 0.1.2"},
{:logfmt, "~> 3.3"},
{:mox, "~> 1.0", only: [:test, :dev]},
{:nimble_csv, "~> 1.1"},
{:oban, "~> 2.11"},
Expand Down
1 change: 0 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"libcluster": {:hex, :libcluster, "3.3.3", "a4f17721a19004cfc4467268e17cff8b1f951befe428975dd4f6f7b84d927fe0", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "7c0a2275a0bb83c07acd17dab3c3bfb4897b145106750eeccc62d302e3bdfee5"},
"libcluster_postgres": {:hex, :libcluster_postgres, "0.1.2", "51380bb6b3a6e11b2614202c63169b464cf4867814da52cc3aa82dfc5ae22248", [:mix], [{:libcluster, "~> 3.3", [hex: :libcluster, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "b957ca609ec5dcddc37342a756bfc027029225bfb089bf0b32974f0ec0cac237"},
"logfmt": {:hex, :logfmt, "3.3.3", "6521ee4a5c532088e15d487fab9f736c07bdd161d643560c73cd4b10685deb65", [:mix], [], "hexpm", "dbd51cd3fe37c3429b9bd687bad1f531a533505f4a641592129e7a47e24104d1"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"},
"mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"},
Expand Down

0 comments on commit 50a99d0

Please sign in to comment.