Luger
Luger is a super simple logging plug for Elixir which logs status codes and IP addresses as well as the route. I basically made it into a module rather than rolling my own logger in every project (seeing as the built-in Plug logger really isn’t very useful).
Includes bindings using pre_plug to ensure that logs are fired even in case of error states.
Installation
As of v1.0.0, Luger is available on Hex. You can install the package via:
Add luger to your list of dependencies in
mix.exs
:def deps do [{:luger, "~> 1.0"}] end
Ensure luger is started before your application:
def application do [applications: [:luger]] end
Usage
Super easy, just like any other plug - just drop it into your router.
You can use plug Luger
, but if you use use Luger
you get some additional safety bindings.
defmodule PlugTest.Router do
# import Conn
import Plug.Conn
# pull in any Plug dependencies
use Plug.ErrorHandler
use Plug.Router
# add the logger
use Luger # or `plug Luger`
# plug requirements
plug :match
plug :dispatch
get "/" do
raise Plug.BadRequestError
end
defp handle_errors(conn, _) do
send_resp(conn, conn.status, "Something went wrong!")
end
end
Options
There are a couple of options you can use to customize the output.
The values shown below are the default values:
plug Luger,
include_ip: true, # ignore ip address (useful if local only)
level: :info # the log message logging level