From 9cb3cafa62f40bea5b7b23ac4619acfc7986359b Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Sat, 21 Nov 2015 22:46:37 +0200 Subject: [PATCH] Add flush on newline Fixes #15 --- spec/logger_spec.cr | 5 ++--- src/kemal/logger.cr | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spec/logger_spec.cr b/spec/logger_spec.cr index 1c22422..82e59d1 100644 --- a/spec/logger_spec.cr +++ b/spec/logger_spec.cr @@ -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 diff --git a/src/kemal/logger.cr b/src/kemal/logger.cr index 1d7743d..9bdfc44 100644 --- a/src/kemal/logger.cr +++ b/src/kemal/logger.cr @@ -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