Add log macro

This commit is contained in:
Sdogruyol 2016-01-08 18:44:37 +02:00
parent 265bfb1db2
commit aabfe4ff99
3 changed files with 14 additions and 4 deletions

View File

@ -18,6 +18,7 @@ describe "Logger" do
logger = Kemal::Logger.new
logger.handler.should be_a File
end
it "writes to a file in production" do
config = Kemal.config
config.env = "production"

View File

@ -34,3 +34,10 @@ end
macro public_folder(path)
Kemal.config.public_folder = {{path}}
end
# Logs to output stream.
# development: STDOUT in
# production: kemal.log
macro log(message)
Kemal::Logger::INSTANCE.write "#{{{message}}}\n"
end

View File

@ -8,8 +8,10 @@ module Kemal::Middleware
# Kemal.config.add_handler auth_handler
#
class HTTPBasicAuth < HTTP::Handler
BASIC = "Basic"
AUTH = "Authorization"
BASIC = "Basic"
AUTH = "Authorization"
AUTH_MESSAGE = "Could not verify your access level for that URL.\nYou have to login with proper credentials"
HEADER_LOGIN_REQUIRED = "Basic realm=\"Login Required\""
def initialize(@username, @password)
end
@ -23,8 +25,8 @@ module Kemal::Middleware
end
end
headers = HTTP::Headers.new
headers["WWW-Authenticate"] = "Basic realm=\"Login Required\""
HTTP::Response.new(401, "Could not verify your access level for that URL.\nYou have to login with proper credentials", headers, nil, "HTTP/1.1", nil)
headers["WWW-Authenticate"] = HEADER_LOGIN_REQUIRED
HTTP::Response.new(401, AUTH_MESSAGE, headers, nil, "HTTP/1.1", nil)
end
def authorized?(value)