mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add logger macro to easily setup custom log_handler
This commit is contained in:
parent
3c75d727ba
commit
8f5bc755ae
5 changed files with 16 additions and 8 deletions
|
@ -29,10 +29,4 @@ describe "Config" do
|
|||
config.handlers.size.should eq(1)
|
||||
end
|
||||
|
||||
it "sets a custom logger" do
|
||||
config = Kemal::Config::INSTANCE
|
||||
config.logger = CustomLogHandler.new("production")
|
||||
config.handlers.first.should be_a(CustomLogHandler)
|
||||
config.logger.should be_a(CustomLogHandler)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,5 +27,12 @@ describe "Macros" do
|
|||
logging false
|
||||
Kemal.config.logging.should eq false
|
||||
end
|
||||
|
||||
it "sets a custom logger" do
|
||||
config = Kemal::Config::INSTANCE
|
||||
logger CustomLogHandler.new("production")
|
||||
config.handlers.first.should be_a(CustomLogHandler)
|
||||
config.logger.should be_a(CustomLogHandler)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ class Kemal::BaseLogHandler < HTTP::Handler
|
|||
end
|
||||
|
||||
def call(context)
|
||||
call_next context
|
||||
end
|
||||
|
||||
def write(message)
|
||||
|
|
|
@ -19,7 +19,6 @@ module Kemal
|
|||
|
||||
def logger=(logger : Kemal::BaseLogHandler)
|
||||
@logger = logger
|
||||
HANDLERS << @logger.not_nil!
|
||||
end
|
||||
|
||||
def scheme
|
||||
|
|
|
@ -34,10 +34,17 @@ end
|
|||
# development: STDOUT in
|
||||
# production: kemal.log
|
||||
macro log(message)
|
||||
Kemal::LogHandler::INSTANCE.write "#{{{message}}}\n" if Kemal.config.logging
|
||||
Kemal.config.logger.write "#{{{message}}}\n"
|
||||
end
|
||||
|
||||
# Enables / Disables logging
|
||||
macro logging(status)
|
||||
Kemal.config.logging = {{status}}
|
||||
end
|
||||
|
||||
macro logger(logger)
|
||||
Kemal.config.logger = {{logger}}
|
||||
Kemal.config.add_handler {{logger}}
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue