Skip to content

Commit

Permalink
Add ability to specify custom logger (#2725)
Browse files Browse the repository at this point in the history
* Add ability to specify custom logger

* Add test

* Use regex match
  • Loading branch information
vzajkov committed Dec 12, 2021
1 parent a25b73d commit 9cf89e6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/puma/dsl.rb
Expand Up @@ -365,6 +365,11 @@ def log_requests(which=true)
@options[:log_requests] = which
end

# Pass in a custom logging class instance
def logger(custom_logger)
@options[:logger] = custom_logger
end

# Show debugging info
#
def debug
Expand Down
13 changes: 13 additions & 0 deletions test/config/custom_logger.rb
@@ -0,0 +1,13 @@
class CustomLogger
def initialize(output=STDOUT)
@output = output
end

def write(msg)
@output.print 'Custom logging: ' + msg
@output.flush
end
end

log_requests
logger CustomLogger.new(STDOUT)
16 changes: 13 additions & 3 deletions test/test_config.rb
Expand Up @@ -59,6 +59,19 @@ def test_ssl_configuration_from_DSL
assert_equal [200, {}, ["embedded app"]], app.call({})
end

def test_custom_logger_from_DSL
conf = Puma::Configuration.new do |c|
c.load "test/config/custom_logger.rb"
end

conf.load
out, _ = capture_subprocess_io do
conf.options[:logger].write('test')
end

assert_match /Custom logging: test/, out
end

def test_ssl_bind
skip_if :jruby
skip_unless :ssl
Expand Down Expand Up @@ -122,9 +135,6 @@ def test_ssl_bind_jruby
assert_equal [ssl_binding], conf.options[:binds]
end




def test_ssl_bind_no_tlsv1_1
skip_if :jruby
skip_unless :ssl
Expand Down

0 comments on commit 9cf89e6

Please sign in to comment.