0.0
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
This is a super simple access log middleware that can be used without any framework dependency
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.14
~> 10.0
~> 3.0

Runtime

>= 0
 Project Readme

Rack::AccessLog

Build Status

This is a middleware for ruby / rack based webservice access logging. The implementation doesn't depend on any webframework or monkey patch.

Installation

Add this line to your application's Gemfile:

gem 'rack-access_log'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-access_log

Usage

First we need a logger that can accept and handle hash messages.

You can use the ruby build in with "custom" formatter.

require 'json'
require 'logger'

json_logger = Logger.new(STDOUT)
json_logger.formatter = proc do |severity, datetime, progname, msg|
  JSON.dump(msg) + "\n"
end

Or you can use logger implementations such as TwP/logging gem

require 'logging'

json_logger = Logging.logger["AccessLog"]
appender = Logging.appenders.stdout(:layout => Logging.layouts.json)
json_logger.add_appenders(appender)

Than use it in our middleware stack

config.ru
require 'rack/access_log'
use Rack::AccessLog, json_logger

require 'rack/response'
run proc{|env| Rack::Response.new.finish }

That's all Folks!

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rack-access_log. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.