resurfaceio / logger-ruby

Log API calls with Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

resurfaceio-logger-ruby

Easily log API requests and responses to your own security data lake.

gem CodeFactor License Contributing

Contents

Requires Ruby 2.x. No other dependencies to conflict with your app.

Add this line to your Gemfile:

gem 'resurfaceio-logger'

Then install with Bundler: bundle install

After installing the gem, add an around_action to your Rails controller.

require 'resurfaceio/all'

class MyController < ApplicationController
  
  around_action HttpLoggerForRails.new(
    url: 'http://localhost:7701/message', 
    rules: 'include debug'
  )

end

After installing the gem, add these lines below to config.ru, before the final 'run' statement.

require 'resurfaceio/all'

use HttpLoggerForRack,
  url: 'http://localhost:7701/message',
  rules: 'include debug'

run <...>

After installing the gem, create a logger and call it from the routes of interest.

require 'sinatra'
require 'resurfaceio/all'

logger = HttpLogger.new(
  url: 'http://localhost:7701/message', 
  rules: 'include debug'
)

get '/' do
  response_body = '<html>Hello World</html>'
  HttpMessage.send(logger, request, response, response_body)
  response_body
end

post '/' do
  status 401
  HttpMessage.send(logger, request, response)
  ''
end

Loggers can be directly integrated into your application using our API. This requires the most effort compared with the options described above, but also offers the greatest flexibility and control.

API documentation

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.

About

Log API calls with Ruby

License:Apache License 2.0


Languages

Language:Ruby 100.0%