Rename common_log_handler and common_exception_handler

This commit is contained in:
Serdar Dogruyol 2017-10-06 20:34:18 +03:00
parent ac56973663
commit 5d737ee8f3
6 changed files with 21 additions and 21 deletions

View File

@ -1,6 +1,6 @@
require "./spec_helper"
describe "Kemal::CommonExceptionHandler" do
describe "Kemal::ExceptionHandler" do
it "renders 404 on route not found" do
get "/" do |env|
"Hello"
@ -10,7 +10,7 @@ describe "Kemal::CommonExceptionHandler" do
io = IO::Memory.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
Kemal::CommonExceptionHandler::INSTANCE.call(context)
Kemal::ExceptionHandler::INSTANCE.call(context)
response.close
io.rewind
response = HTTP::Client::Response.from_io(io, decompress: false)
@ -28,8 +28,8 @@ describe "Kemal::CommonExceptionHandler" do
io = IO::Memory.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
Kemal::CommonExceptionHandler::INSTANCE.call(context)
Kemal::ExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
Kemal::ExceptionHandler::INSTANCE.call(context)
response.close
io.rewind
response = HTTP::Client::Response.from_io(io, decompress: false)
@ -49,8 +49,8 @@ describe "Kemal::CommonExceptionHandler" do
io = IO::Memory.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
Kemal::CommonExceptionHandler::INSTANCE.call(context)
Kemal::ExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
Kemal::ExceptionHandler::INSTANCE.call(context)
response.close
io.rewind
response = HTTP::Client::Response.from_io(io, decompress: false)
@ -71,8 +71,8 @@ describe "Kemal::CommonExceptionHandler" do
io = IO::Memory.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
Kemal::CommonExceptionHandler::INSTANCE.call(context)
Kemal::ExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
Kemal::ExceptionHandler::INSTANCE.call(context)
response.close
io.rewind
response = HTTP::Client::Response.from_io(io, decompress: false)
@ -93,8 +93,8 @@ describe "Kemal::CommonExceptionHandler" do
io = IO::Memory.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
Kemal::CommonExceptionHandler::INSTANCE.call(context)
Kemal::ExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
Kemal::ExceptionHandler::INSTANCE.call(context)
response.close
io.rewind
response = HTTP::Client::Response.from_io(io, decompress: false)

View File

@ -1,10 +1,10 @@
require "./spec_helper"
describe "Kemal::CommonLogHandler" do
describe "Kemal::LogHandler" do
it "logs to the given IO" do
config = Kemal.config
io = IO::Memory.new
logger = Kemal::CommonLogHandler.new io
logger = Kemal::LogHandler.new io
logger.write "Something"
io.to_s.should eq "Something"
end
@ -15,7 +15,7 @@ describe "Kemal::CommonLogHandler" do
context_io = IO::Memory.new
response = HTTP::Server::Response.new(context_io)
context = HTTP::Server::Context.new(request, response)
logger = Kemal::CommonLogHandler.new io
logger = Kemal::LogHandler.new io
logger.call(context)
io.to_s.should_not be nil
end

View File

@ -117,7 +117,7 @@ module Kemal
private def setup_log_handler
@logger ||= if @logging
Kemal::CommonLogHandler.new
Kemal::LogHandler.new
else
Kemal::NullLogHandler.new
end
@ -127,7 +127,7 @@ module Kemal
private def setup_error_handler
if @always_rescue
@error_handler ||= Kemal::CommonExceptionHandler.new
@error_handler ||= Kemal::ExceptionHandler.new
HANDLERS.insert(@handler_position, @error_handler.not_nil!)
@handler_position += 1
end

View File

@ -1,6 +1,6 @@
module Kemal
# Handles all the exceptions, including 404, custom errors and 500.
class CommonExceptionHandler
class ExceptionHandler
include HTTP::Handler
INSTANCE = new

View File

@ -3,8 +3,8 @@
# goes between the first 4 and the last `Kemal::RouteHandler`.
#
# - `Kemal::InitHandler`
# - `Kemal::CommonLogHandler`
# - `Kemal::CommonExceptionHandler`
# - `Kemal::LogHandler`
# - `Kemal::ExceptionHandler`
# - `Kemal::StaticFileHandler`
# - Here goes custom handlers
# - `Kemal::RouteHandler`
@ -24,7 +24,7 @@ def public_folder(path : String)
end
# Logs the output via `logger`.
# This is the built-in `Kemal::CommonLogHandler` by default which uses STDOUT.
# This is the built-in `Kemal::LogHandler` by default which uses STDOUT.
def log(message : String)
Kemal.config.logger.write "#{message}\n"
end
@ -39,7 +39,7 @@ def logging(status : Bool)
Kemal.config.logging = status
end
# This is used to replace the built-in `Kemal::CommonLogHandler` with a custom logger.
# This is used to replace the built-in `Kemal::LogHandler` with a custom logger.
#
# A custom logger must inherit from `Kemal::BaseLogHandler` and must implement
# `call(env)`, `write(message)` methods.

View File

@ -1,6 +1,6 @@
module Kemal
# Uses `STDOUT` by default and handles the logging of request/response process time.
class CommonLogHandler < Kemal::BaseLogHandler
class LogHandler < Kemal::BaseLogHandler
@io : IO
def initialize(@io : IO = STDOUT)