mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Improve logging and specs
This commit is contained in:
parent
dc3cc74798
commit
98efbfe341
7 changed files with 41 additions and 30 deletions
|
@ -1,14 +1,7 @@
|
|||
module Kemal
|
||||
# All loggers must inherit from `Kemal::BaseLogHandler`.
|
||||
class Kemal::BaseLogHandler < HTTP::Handler
|
||||
def initialize
|
||||
end
|
||||
|
||||
def call(context)
|
||||
call_next context
|
||||
end
|
||||
|
||||
def write(message)
|
||||
end
|
||||
abstract class Kemal::BaseLogHandler < HTTP::Handler
|
||||
abstract def call(context)
|
||||
abstract def write(message)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
module Kemal
|
||||
class CommonLogHandler < Kemal::BaseLogHandler
|
||||
@handler : IO::FileDescriptor
|
||||
getter handler
|
||||
@handler : IO
|
||||
|
||||
def initialize
|
||||
@handler = STDOUT
|
||||
def initialize(io : IO)
|
||||
@handler = io
|
||||
end
|
||||
|
||||
def call(context)
|
||||
|
|
|
@ -74,7 +74,7 @@ module Kemal
|
|||
|
||||
private def setup_log_handler
|
||||
@logger ||= if @logging
|
||||
Kemal::CommonLogHandler.new
|
||||
Kemal::CommonLogHandler.new(STDOUT)
|
||||
else
|
||||
Kemal::NullLogHandler.new
|
||||
end
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
module Kemal
|
||||
# This is here to represent the logger corresponding to Null Object Pattern.
|
||||
class NullLogHandler < Kemal::BaseLogHandler
|
||||
def call(context)
|
||||
end
|
||||
|
||||
def write(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue