Skip to content

Commit

Permalink
Fix deprecated LogHandler.new(IO)
Browse files Browse the repository at this point in the history
  • Loading branch information
waj committed Apr 23, 2020
1 parent 1a86862 commit 5c9e79c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions spec/std/http/server/handlers/log_handler_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ describe HTTP::LogHandler do
)
end

it "logs to io" do
request = HTTP::Request.new("GET", "/")
response = HTTP::Server::Response.new(IO::Memory.new)
context = HTTP::Server::Context.new(request, response)

backend = Log::MemoryBackend.new
io = IO::Memory.new
handler = HTTP::LogHandler.new(io)
handler.next = ->(ctx : HTTP::Server::Context) {}
handler.call(context)

io.to_s.should match(%r(- - GET / HTTP/1.1 - 200 \(\d+(\.\d+)?[mµn]s\)$))
end

it "log failed request" do
io = IO::Memory.new
request = HTTP::Request.new("GET", "/")
Expand Down
2 changes: 1 addition & 1 deletion src/http/server/handlers/log_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class HTTP::LogHandler

@[Deprecated("Use `new([Log])` instead")]
def initialize(io : IO)
@log = Log.for("http.server")
@log = Log.new("http.server", Log::IOBackend.new(io), :info)
end

def initialize(@log = Log.for("http.server"))
Expand Down

0 comments on commit 5c9e79c

Please sign in to comment.