diff --git a/lib/puma/cli.rb b/lib/puma/cli.rb index 0fadffdd..a8c91a33 100644 --- a/lib/puma/cli.rb +++ b/lib/puma/cli.rb @@ -491,7 +491,7 @@ module Puma set_rack_environment if clustered? - @events = PidEvents.new STDOUT, STDERR + @events.formatter = Events::PidFormatter.new @options[:logger] = @events @runner = Cluster.new(self) diff --git a/lib/puma/events.rb b/lib/puma/events.rb index 2c3325a8..c90ebaae 100644 --- a/lib/puma/events.rb +++ b/lib/puma/events.rb @@ -8,12 +8,24 @@ module Puma # The methods available are the events that the Server fires. # class Events + class DefaultFormatter + def call(str) + str + end + end + + class PidFormatter + def call(str) + "[#{$$}] #{str}" + end + end include Const # Create an Events object that prints to +stdout+ and +stderr+. # def initialize(stdout, stderr) + @formatter = DefaultFormatter.new @stdout = stdout @stderr = stderr @@ -28,6 +40,7 @@ module Puma end attr_reader :stdout, :stderr + attr_accessor :formatter # Fire callbacks for the named hook # @@ -52,11 +65,11 @@ module Puma # Write +str+ to +@stdout+ # def log(str) - @stdout.puts str + @stdout.puts format(str) end def write(str) - @stdout.write str + @stdout.write format(str) end def debug(str) @@ -66,10 +79,14 @@ module Puma # Write +str+ to +@stderr+ # def error(str) - @stderr.puts "ERROR: #{str}" + @stderr.puts format("ERROR: #{str}") exit 1 end + def format(str) + formatter.call(str) + end + # An HTTP parse error has occured. # +server+ is the Server object, +env+ the request, and +error+ a # parsing exception. @@ -113,18 +130,4 @@ module Puma Events.new $stdout, $stderr end end - - class PidEvents < Events - def log(str) - super "[#{$$}] #{str}" - end - - def write(str) - super "[#{$$}] #{str}" - end - - def error(str) - super "[#{$$}] #{str}" - end - end end