mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Start decoupling logger
This commit is contained in:
parent
ffc3d6d224
commit
850af8819e
6 changed files with 15 additions and 12 deletions
|
@ -5,8 +5,6 @@ at_exit do
|
|||
Kemal::CLI.new
|
||||
config = Kemal.config
|
||||
if config.logging
|
||||
logger = Kemal::LogHandler.new
|
||||
config.logger = logger
|
||||
config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n"
|
||||
end
|
||||
config.add_handler Kemal::StaticFileHandler.new(config.public_folder)
|
||||
|
|
|
@ -2,7 +2,7 @@ module Kemal
|
|||
class Config
|
||||
INSTANCE = Config.new
|
||||
HANDLERS = [] of HTTP::Handler
|
||||
property host_binding, ssl, port, env, public_folder, logging
|
||||
property host_binding, ssl, port, env, public_folder, logging, logger
|
||||
|
||||
def initialize
|
||||
@host_binding = "0.0.0.0" unless @host_binding
|
||||
|
@ -10,7 +10,7 @@ module Kemal
|
|||
@env = "development" unless @env
|
||||
@public_folder = "./public"
|
||||
@logging = true
|
||||
@logger = nil
|
||||
@logger = Kemal::LogHandler.new(@env) unless @logging
|
||||
end
|
||||
|
||||
def scheme
|
||||
|
|
|
@ -2,11 +2,10 @@ require "colorize"
|
|||
require "http"
|
||||
|
||||
class Kemal::LogHandler < HTTP::Handler
|
||||
INSTANCE = new
|
||||
# INSTANCE = new
|
||||
getter handler
|
||||
|
||||
def initialize
|
||||
@env = Kemal.config.env
|
||||
def initialize(@env)
|
||||
@handler = if @env == "production"
|
||||
handler = File.new("kemal.log", "a")
|
||||
handler.flush_on_newline = true
|
||||
|
|
|
@ -35,7 +35,7 @@ class Kemal::RouteHandler < HTTP::Handler
|
|||
context.response.print body
|
||||
return context
|
||||
rescue ex
|
||||
Kemal::LogHandler::INSTANCE.write "Exception: #{ex.to_s}\n"
|
||||
# Kemal.config.logger.write "Exception: #{ex.to_s}\n"
|
||||
return render_500(context, ex.to_s)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue