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

@ -18,8 +18,7 @@ describe "Logger" do
logger = Kemal::Logger.new
logger.handler.should be_a File
end
#TODO: Check https://github.com/manastech/crystal/issues/1899
it "writes to a file in production" do
config = Kemal.config
config.env = "production"
@ -28,6 +27,6 @@ describe "Logger" do
logger.call request
str = File.read("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

View File

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