More logger specs
This commit is contained in:
parent
0e23e8d9a3
commit
f66e9cd834
2 changed files with 21 additions and 5 deletions
|
@ -1,6 +1,11 @@
|
||||||
require "./spec_helper"
|
require "./spec_helper"
|
||||||
|
|
||||||
describe "Logger" do
|
describe "Logger" do
|
||||||
|
it "creates a handler" do
|
||||||
|
logger = Kemal::Logger.new
|
||||||
|
logger.handler.should_not be nil
|
||||||
|
end
|
||||||
|
|
||||||
it "creates a STDOUT handler by default" do
|
it "creates a STDOUT handler by default" do
|
||||||
config = Kemal.config
|
config = Kemal.config
|
||||||
logger = Kemal::Logger.new
|
logger = Kemal::Logger.new
|
||||||
|
@ -13,4 +18,15 @@ describe "Logger" do
|
||||||
logger = Kemal::Logger.new
|
logger = Kemal::Logger.new
|
||||||
logger.handler.should be_a File
|
logger.handler.should be_a File
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "writes to a file in production" do
|
||||||
|
config = Kemal.config
|
||||||
|
config.env = "production"
|
||||||
|
logger = Kemal::Logger.new
|
||||||
|
request = HTTP::Request.new("GET", "/?message=world&time=now")
|
||||||
|
logger.call request
|
||||||
|
str = File.read("kemal.log")
|
||||||
|
File.delete("kemal.log")
|
||||||
|
str.includes?("GET /?message=world&time=now").should eq true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ 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+")
|
File.new("kemal.log", "a")
|
||||||
else
|
else
|
||||||
STDOUT
|
STDOUT
|
||||||
end
|
end
|
||||||
|
@ -35,7 +35,7 @@ class Kemal::Logger < HTTP::Handler
|
||||||
|
|
||||||
def write(message)
|
def write(message)
|
||||||
if @env == "production"
|
if @env == "production"
|
||||||
@handler.write message.to_slice
|
File.write "kemal.log", message
|
||||||
else
|
else
|
||||||
@handler.print message
|
@handler.print message
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue