An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

# resurfaceio-logger-ruby
Easily log API requests and responses to your own security data lake.

[![gem](https://badge.fury.io/rb/resurfaceio-logger.svg)](https://badge.fury.io/rb/resurfaceio-logger)
[![CodeFactor](https://www.codefactor.io/repository/github/resurfaceio/logger-ruby/badge)](https://www.codefactor.io/repository/github/resurfaceio/logger-ruby)
[![License](https://img.shields.io/github/license/resurfaceio/logger-ruby)](https://github.com/resurfaceio/logger-ruby/blob/master/LICENSE)
[![Contributing](https://img.shields.io/badge/contributions-welcome-green.svg)](https://github.com/resurfaceio/logger-ruby/blob/master/CONTRIBUTING.md)

## Contents

## 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.

Logging rules documentation

---
© 2016-2024 Graylog, Inc.