0.0
The project is in a healthy, maintained state
Rack middleware that logs API request details (method, path, IP, duration, status, errors) into a CSV or JSON file. Supports daily rotation and format customization.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 0
>= 0
 Project Readme

ApiHitLogger

Rack middleware to log all API request details into a rotating CSV log file.

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add api_hit_logger

If bundler is not being used to manage dependencies, install the gem by executing:

gem install api_hit_logger

Usage

To enable request logging with ApiHitLogger, simply add the middleware to your Rails or Rack-based application:

  1. Require the gem In your config/application.rb or equivalent setup file: require 'api_hit_logger'

  2. Add the middleware

For Rails: config/application.rb config.middleware.use ApiHitLogger::Middleware

For Rack apps, update your config.ru: use ApiHitLogger::Middleware

Once set up, all incoming HTTP requests will be logged to a CSV file in the log/ directory, with a separate file generated for each day.

No additional configuration is required for basic usage.

Log File Location The logs are written to: log/api_hit_logs_YYYY-MM-DD.csv

Each day's requests are stored in their own CSV/JSON file.

Configuration

To customize how API hits are logged, create a file at:

With the following content:

ApiHitLogger.configure do |config|
  # Format options: :csv, :json (default: :csv)
  config.log_format = :csv
end

If no initializer is present, default settings will be used.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/chaitanyag1-c/api_hit_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/chaitanyag1-c/api_hit_logger/blob/master/CODE_OF_CONDUCT.md).

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Code of Conduct

Everyone interacting in the ApiHitLogger project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/chaitanyag1-c/api_hit_logger/blob/master/CODE_OF_CONDUCT.md).