diff --git a/lib/puma/dsl.rb b/lib/puma/dsl.rb index 308a9687fe..21f3818cc1 100644 --- a/lib/puma/dsl.rb +++ b/lib/puma/dsl.rb @@ -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 diff --git a/test/config/custom_logger.rb b/test/config/custom_logger.rb new file mode 100644 index 0000000000..0794625f38 --- /dev/null +++ b/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) diff --git a/test/test_config.rb b/test/test_config.rb index 758910ca18..b478441813 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -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 @@ -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