Skip to content

Instantly share code, notes, and snippets.

@jamesduncombe
Last active November 13, 2018 12:06
Show Gist options
  • Save jamesduncombe/bd1b851385be84815f2d32483374996c to your computer and use it in GitHub Desktop.
Save jamesduncombe/bd1b851385be84815f2d32483374996c to your computer and use it in GitHub Desktop.
Sinatra basic setup
# Mock app for Timber.io
# Ruby v2.2.1p85
# Sinatra v1.4.7
# Started with just `rackup`
require 'bundler'
Bundler.require
require 'json'
Timber::Integrations::Rack.middlewares.each do |middleware|
use middleware
end
log_device = Timber::LogDevices::HTTP.new('my key')
logger = Timber::Logger.new(log_device)
# Pretty sure this might be the issue... this is common log type output right?
use Rack::CommonLogger, logger
get '/' do
"test endpoint"
end
run Sinatra::Application

When I run that with rackup I get this on the output (after hitting the endpoint with curl localhost:9292):

[2018-11-13 12:02:11] INFO  WEBrick 1.3.1
[2018-11-13 12:02:11] INFO  ruby 2.2.1 (2015-02-26) [x86_64-darwin14]
[2018-11-13 12:02:11] INFO  WEBrick::HTTPServer#start: pid=15625 port=9292
Started GET "/" [http_request]
Completed 200 OK , 13 bytes, in 23.689ms [http_response]
::1 - - [13/Nov/2018:12:02:16 +0000] "GET / HTTP/1.1" 200 13 0.0276

From that I can see that the middleware is kicking in by decorating the request log output, but, it's the Common Log that gets sent to Timber.io (which, makes sense as I've told Sinatra to use the Rack::CommonLogger). However, how do I redirect the decorated logs correctly?

In the console on Timber.io I get:

Nov 13 12:02:16pm info "GET / HTTP/1.1" 200 13 0.0253

... which just seems to be the Common Log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment