LogSpy
LogSpy is a Rack middleware sending request log to Amazon SQS.
After each request, log_spy opens a new thread and sends the request log payload as a json string onto AWS SQS.
Installation
Add this line to your application's Gemfile:
gem 'log_spy'
And then execute:
$ bundle
Or install it yourself as:
$ gem install log_spy
Usage
require and use the middleware:
- bare rack:
require 'log_spy'
use LogSpy::Spy, 'aws-sqs-url'
- rails:
ruby # application.rb config.middleware.use LogSpy::Spy, 'aws-sqs-url', :reigon => 'ap-southeast-1'
API Documents:
to use the middleware:
- usage:
use LogSpy::Spy, <aws-sqs-url>[, <options>] - params:
the payload format sends to AWS SQS:
{
"path": "/the/request/path",
"status": 200,
"execution_time": 145.3, // in ms
"request": {
"content_type": "application/json",
"request_method": "post",
"ip": "123.1.1.1",
"query_string": "query-key=query-val&hello=world",
"body": "body-key=body-val"
},
// if got exception
"error": {
"message": "the exception message",
"backtrace": [ "exception back trace" ]
}
}
error:errorwould not be included in the payload if no exception was raisedrequest.body: if the requestContent-Typeis ofmultipart, the body would be an empty string
Testing:
$ bundle install
$ bundle exec rspec spec/
Contributing
- Fork it ( https://github.com/[my-github-username]/log_spy/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request