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)
|
config.handlers.size.should eq(1)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -27,5 +27,12 @@ describe "Macros" do
|
||||||
logging false
|
logging false
|
||||||
Kemal.config.logging.should eq false
|
Kemal.config.logging.should eq false
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ class Kemal::BaseLogHandler < HTTP::Handler
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(context)
|
def call(context)
|
||||||
|
call_next context
|
||||||
end
|
end
|
||||||
|
|
||||||
def write(message)
|
def write(message)
|
||||||
|
|
|
@ -19,7 +19,6 @@ module Kemal
|
||||||
|
|
||||||
def logger=(logger : Kemal::BaseLogHandler)
|
def logger=(logger : Kemal::BaseLogHandler)
|
||||||
@logger = logger
|
@logger = logger
|
||||||
HANDLERS << @logger.not_nil!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def scheme
|
def scheme
|
||||||
|
|
|
@ -34,10 +34,17 @@ end
|
||||||
# development: STDOUT in
|
# development: STDOUT in
|
||||||
# production: kemal.log
|
# production: kemal.log
|
||||||
macro log(message)
|
macro log(message)
|
||||||
Kemal::LogHandler::INSTANCE.write "#{{{message}}}\n" if Kemal.config.logging
|
Kemal.config.logger.write "#{{{message}}}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Enables / Disables logging
|
# Enables / Disables logging
|
||||||
macro logging(status)
|
macro logging(status)
|
||||||
Kemal.config.logging = {{status}}
|
Kemal.config.logging = {{status}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macro logger(logger)
|
||||||
|
Kemal.config.logger = {{logger}}
|
||||||
|
Kemal.config.add_handler {{logger}}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue