PlugLoggerWithMeta

PlugLoggerWithMeta is a Plug.Logger based on Plug.Logger code, focused on metadata logging.

Why

Plug.Logger does not use Logger.metadata, so some useful information such as method and request_path are embedded into the log message hence they must be scraped.

PlugLoggerWithMeta makes them machine readable by exporting them using Logger.metadata.

There are also other similar libraries, however this tries to behave as close as possible to Plug.Logger.

Installation

def deps do
  [
    {:plug_logger_with_meta, "~> 0.1"}
  ]
end
--- a/endpoint.ex
+++ b/endpoint.ex
@@ -38,7 +38,7 @@ defmodule MyProject.APIWeb.Endpoint do
   end
 
   plug Plug.RequestId
-  plug Plug.Logger
+  plug PlugLoggerWithMeta
 config :logger, :console, format: "[$level] $message\n"
+  metadata: [
+    :method,
+    :request_path,
+    :status_code,
+    :elapsed,
+  ]

pretty_log will format all metadata using logfmt.

Available Metadata

About This Project

This project has been created in order to provide better logs in Astarte. We are open to any contribution and we encourage adoption of this library, also outside Astarte, in order to provide better logs to everyone.