mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Complete decoupling logger
This commit is contained in:
parent
52538afb10
commit
3c75d727ba
9 changed files with 53 additions and 28 deletions
|
@ -31,7 +31,8 @@ describe "Config" do
|
|||
|
||||
it "sets a custom logger" do
|
||||
config = Kemal::Config::INSTANCE
|
||||
config.logger = CustomTestHandler.new
|
||||
config.handlers.first.should be_a(CustomTestHandler)
|
||||
config.logger = CustomLogHandler.new("production")
|
||||
config.handlers.first.should be_a(CustomLogHandler)
|
||||
config.logger.should be_a(CustomLogHandler)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,27 +2,27 @@ require "./spec_helper"
|
|||
|
||||
describe "Kemal::LogHandler" do
|
||||
it "creates a handler" do
|
||||
logger = Kemal::LogHandler.new "production"
|
||||
logger = Kemal::CommonLogHandler.new "production"
|
||||
logger.handler.should_not be nil
|
||||
end
|
||||
|
||||
it "creates a STDOUT handler by default" do
|
||||
config = Kemal.config
|
||||
logger = Kemal::LogHandler.new "production"
|
||||
logger = Kemal::CommonLogHandler.new "production"
|
||||
logger.handler.should be_a IO
|
||||
end
|
||||
|
||||
it "creates a file handler in production" do
|
||||
config = Kemal.config
|
||||
config.env = "production"
|
||||
logger = Kemal::LogHandler.new "production"
|
||||
logger = Kemal::CommonLogHandler.new "production"
|
||||
logger.handler.should be_a File
|
||||
end
|
||||
|
||||
it "writes to a file in production" do
|
||||
config = Kemal.config
|
||||
config.env = "production"
|
||||
logger = Kemal::LogHandler.new "production"
|
||||
logger = Kemal::CommonLogHandler.new "production"
|
||||
request = HTTP::Request.new("GET", "/?message=world&time=now")
|
||||
io = MemoryIO.new
|
||||
response = HTTP::Server::Response.new(io)
|
||||
|
|
|
@ -10,6 +10,8 @@ class CustomTestHandler < HTTP::Handler
|
|||
end
|
||||
end
|
||||
|
||||
class CustomLogHandler < Kemal::BaseLogHandler; end
|
||||
|
||||
def create_request_and_return_io(handler, request)
|
||||
io = MemoryIO.new
|
||||
response = HTTP::Server::Response.new(io)
|
||||
|
@ -34,6 +36,8 @@ def create_ws_request_and_return_io(handler, request)
|
|||
end
|
||||
|
||||
Spec.before_each do
|
||||
Kemal.config.env = "development"
|
||||
Kemal.config.handlers.clear
|
||||
config = Kemal.config
|
||||
config.env = "development"
|
||||
config.setup_logging
|
||||
config.handlers.clear
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue