Plug.AccessLog

Plug for writing access logs.

Setup

To use the plug in your projects, edit your mix.exs file and add the project as a dependency:

defp deps do
  [ { :plug_accesslog, "~> 0.1" } ]
end

You should also update your applications to start the plug:

def application do
  [ applications: [ :plug_accesslog ] ]
end

Usage

The easiest way to use the plug is to add it to your existing router:

defmodule AppRouter do
  use Plug.Router

  plug Plug.AccessLog,
    format: :default,
    logfile: "/path/to/your/logs/access.log"

  plug :match
  plug :dispatch

  get "/hello" do
    send_resp(conn, 200, "world")
  end

  match _ do
    send_resp(conn, 404, "oops")
  end
end

Log Format

The default format is CLF:

"%h %l %u %t \"%r\" %>s %b"
---

The following formatting directives are available:

Note for %b: To determine the size of the response the “Content-Length” (exact case match required for now!) will be inspected and, if available, returned unverified. If the header is not present the response body will be inspected using byte_size/1.

Note for %h: The hostname will always be the ip of the client.

Note for %l: Always a dash (“-“).

Note for %r: For now the http version is always logged as “HTTP/1.1”, regardless of the true http version.

Note for %u: Currently not supported, defaults to a dash (“-“).

License

Apache License, Version 2.0