Skip to content

Commit

Permalink
fix(ConsoleSink): allow non async console logging
Browse files Browse the repository at this point in the history
The async attribute was being set to true by default using the or construct, making it impossible to pass false as value. Add missing test.
  • Loading branch information
Tastyep committed Jan 8, 2023
1 parent 68a5fa8 commit 45b26a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/structlog/sinks/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ setmetatable(Console, {

function Console:new(async)
local console = {
async = async or true,
async = async,
}

Console.__index = Console
Expand Down
21 changes: 21 additions & 0 deletions test/unit/sinks/console_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local log = require("structlog")
local Console = log.sinks.Console

local stub = require("luassert.stub")

describe("Console constructor", function()
local handler = {}
stub(handler, "handle")

it("should create an async console logger", function()
local sink = Console(true)

assert.True(sink.async)
end)

it("should create an non-async console logger", function()
local sink = Console(false)

assert.False(sink.async)
end)
end)

0 comments on commit 45b26a2

Please sign in to comment.