From 5d737ee8f33f36af24fc4d316e0dd275875afee7 Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol Date: Fri, 6 Oct 2017 20:34:18 +0300 Subject: [PATCH] Rename common_log_handler and common_exception_handler --- spec/common_exception_handler_spec.cr | 20 +++++++++---------- spec/common_log_handler_spec.cr | 6 +++--- src/kemal/config.cr | 4 ++-- ...eption_handler.cr => exception_handler.cr} | 2 +- src/kemal/helpers/helpers.cr | 8 ++++---- .../{common_log_handler.cr => log_handler.cr} | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) rename src/kemal/{common_exception_handler.cr => exception_handler.cr} (97%) rename src/kemal/{common_log_handler.cr => log_handler.cr} (93%) diff --git a/spec/common_exception_handler_spec.cr b/spec/common_exception_handler_spec.cr index 75ff2e9..63490c7 100644 --- a/spec/common_exception_handler_spec.cr +++ b/spec/common_exception_handler_spec.cr @@ -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) diff --git a/spec/common_log_handler_spec.cr b/spec/common_log_handler_spec.cr index 1e4585c..e715cbd 100644 --- a/spec/common_log_handler_spec.cr +++ b/spec/common_log_handler_spec.cr @@ -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 diff --git a/src/kemal/config.cr b/src/kemal/config.cr index 70ba92a..8f7ff8b 100644 --- a/src/kemal/config.cr +++ b/src/kemal/config.cr @@ -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 diff --git a/src/kemal/common_exception_handler.cr b/src/kemal/exception_handler.cr similarity index 97% rename from src/kemal/common_exception_handler.cr rename to src/kemal/exception_handler.cr index 1a1f883..155fbe3 100644 --- a/src/kemal/common_exception_handler.cr +++ b/src/kemal/exception_handler.cr @@ -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 diff --git a/src/kemal/helpers/helpers.cr b/src/kemal/helpers/helpers.cr index 2a2b87a..b57a48b 100644 --- a/src/kemal/helpers/helpers.cr +++ b/src/kemal/helpers/helpers.cr @@ -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. diff --git a/src/kemal/common_log_handler.cr b/src/kemal/log_handler.cr similarity index 93% rename from src/kemal/common_log_handler.cr rename to src/kemal/log_handler.cr index 9643434..2256492 100644 --- a/src/kemal/common_log_handler.cr +++ b/src/kemal/log_handler.cr @@ -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)