Add flush on newline Fixes #15

This commit is contained in:
Sdogruyol 2015-11-21 22:46:37 +02:00
parent 173bbf7639
commit 9cb3cafa62
2 changed files with 5 additions and 4 deletions

View file

@ -19,7 +19,6 @@ describe "Logger" do
logger.handler.should be_a File logger.handler.should be_a File
end end
#TODO: Check https://github.com/manastech/crystal/issues/1899
it "writes to a file in production" do it "writes to a file in production" do
config = Kemal.config config = Kemal.config
config.env = "production" config.env = "production"
@ -28,6 +27,6 @@ describe "Logger" do
logger.call request logger.call request
str = File.read("kemal.log") str = File.read("kemal.log")
File.delete("kemal.log") File.delete("kemal.log")
str.includes?("GET /?message=world&time=now").should eq false str.includes?("GET /?message=world&time=now").should eq true
end end
end end

View file

@ -4,7 +4,9 @@ class Kemal::Logger < HTTP::Handler
def initialize def initialize
@env = Kemal.config.env @env = Kemal.config.env
@handler = if @env == "production" @handler = if @env == "production"
File.new("kemal.log", "a") handler = File.new("kemal.log", "a")
handler.flush_on_newline = true
handler
else else
STDOUT STDOUT
end end