Optimize CommonLogHandler to directly use the handler instead of string interpolation

This commit is contained in:
Sdogruyol 2016-07-05 20:11:03 +03:00
parent 212ea8707d
commit ae25d0a774

View file

@ -17,9 +17,9 @@ class Kemal::CommonLogHandler < Kemal::BaseLogHandler
def call(context) def call(context)
time = Time.now time = Time.now
call_next(context) call_next(context)
elapsed = Time.now - time elapsed_text = elapsed_text(Time.now - time)
elapsed_text = elapsed_text(elapsed) @handler << time << " " << context.response.status_code << " " << context.request.method << " " << context.request.resource << " " << elapsed_text << "\n"
write "#{time} #{context.response.status_code} #{context.request.method} #{context.request.resource} - #{elapsed_text}\n" @handler.rewind
context context
end end
@ -35,12 +35,4 @@ class Kemal::CommonLogHandler < Kemal::BaseLogHandler
"#{(millis * 1000).round(2)}µs" "#{(millis * 1000).round(2)}µs"
end end
def write(message)
if @env == "production"
@handler.write message.to_slice
else
@handler.print message
end
end
end end