Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't depend on Rack::Logger. #2029

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
require 'sinatra/show_exceptions'
require 'sinatra/version'

require_relative 'middleware/logger'

module Sinatra
# The request object. See Rack::Request for more info:
# https://rubydoc.info/github/rack/rack/main/Rack/Request
Expand Down Expand Up @@ -1835,7 +1837,7 @@ def setup_logging(builder)
end

def setup_null_logger(builder)
builder.use Rack::NullLogger
builder.use Sinatra::Middleware::Logger, ::Logger::FATAL
end

def setup_common_logger(builder)
Expand All @@ -1844,9 +1846,9 @@ def setup_common_logger(builder)

def setup_custom_logger(builder)
if logging.respond_to? :to_int
builder.use Rack::Logger, logging
builder.use Sinatra::Middleware::Logger, logging
else
builder.use Rack::Logger
builder.use Sinatra::Middleware::Logger
end
end

Expand Down
21 changes: 21 additions & 0 deletions lib/sinatra/middleware/logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'logger'

module Sinatra
module Middleware
class Logger
def initialize(app, level = ::Logger::INFO)
@app, @level = app, level
end

def call(env)
logger = ::Logger.new(env[Rack::RACK_ERRORS])
logger.level = @level

env[Rack::RACK_LOGGER] = logger
@app.call(env)
end
end
end
end
1 change: 1 addition & 0 deletions sinatra.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ RubyGems 2.0 or newer is required to protect against public gem pushes. You can
s.add_dependency 'rack-session', '>= 2.0.0', '< 3'
s.add_dependency 'rack-protection', version
s.add_dependency 'tilt', '~> 2.0'
s.add_dependency 'logger'
end
Loading