https://github.com/resurfaceio/logger-ruby
Log API calls with Ruby
https://github.com/resurfaceio/logger-ruby
api-logger http-logger logger-ruby rack-middleware ruby sinatra
Last synced: about 1 month ago
JSON representation
Log API calls with Ruby
- Host: GitHub
- URL: https://github.com/resurfaceio/logger-ruby
- Owner: resurfaceio
- License: apache-2.0
- Created: 2016-01-23T20:21:53.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-02-29T01:24:41.000Z (about 1 year ago)
- Last Synced: 2025-03-27T05:12:16.266Z (about 2 months ago)
- Topics: api-logger, http-logger, logger-ruby, rack-middleware, ruby, sinatra
- Language: Ruby
- Homepage:
- Size: 338 KB
- Stars: 7
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# resurfaceio-logger-ruby
Easily log API requests and responses to your own security data lake.[](https://badge.fury.io/rb/resurfaceio-logger)
[](https://www.codefactor.io/repository/github/resurfaceio/logger-ruby)
[](https://github.com/resurfaceio/logger-ruby/blob/master/LICENSE)
[](https://github.com/resurfaceio/logger-ruby/blob/master/CONTRIBUTING.md)## Contents
- Dependencies
- Installing With Bundler
- Logging From Rails Controller
- Logging From Rack Middleware
- Logging From Sinatra
- Logging With API
- Protecting User Privacy
## Dependencies
Requires Ruby 2.x. No other dependencies to conflict with your app.
## Installing With Bundler
Add this line to your Gemfile:
```
gem 'resurfaceio-logger'
```
Then install with Bundler: `bundle install`
## Logging From Rails Controller
After installing the gem, add an `around_action` to your Rails controller.
```ruby
require 'resurfaceio/all'
class MyController < ApplicationController
around_action HttpLoggerForRails.new(
url: 'http://localhost:7701/message',
rules: 'include debug'
)
end
```
## Logging From Rack Middleware
After installing the gem, add these lines below to `config.ru`, before the final
'run' statement.
```ruby
require 'resurfaceio/all'
use HttpLoggerForRack,
url: 'http://localhost:7701/message',
rules: 'include debug'
run <...>
```
## Logging From Sinatra
After installing the gem, create a logger and call it from the routes of interest.
```ruby
require 'sinatra'
require 'resurfaceio/all'
logger = HttpLogger.new(
url: 'http://localhost:7701/message',
rules: 'include debug'
)
get '/' do
response_body = 'Hello World'
HttpMessage.send(logger, request, response, response_body)
response_body
end
post '/' do
status 401
HttpMessage.send(logger, request, response)
''
end
```
## Logging With API
Loggers can be directly integrated into your application using our [API](API.md). This requires the most effort compared with
the options described above, but also offers the greatest flexibility and control.
[API documentation](API.md)
## Protecting User Privacy
Loggers always have an active set of rules that control what data is logged
and how sensitive data is masked. All of the examples above apply a predefined set of rules (`include debug`),
but logging rules are easily customized to meet the needs of any application.
---
© 2016-2024 Graylog, Inc.