From 45b26a2b1036bb93c0e83f4225e85ab3cee8f476 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Sun, 8 Jan 2023 09:41:42 +0100 Subject: [PATCH] fix(ConsoleSink): allow non async console logging 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. --- lua/structlog/sinks/console.lua | 2 +- test/unit/sinks/console_spec.lua | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/unit/sinks/console_spec.lua diff --git a/lua/structlog/sinks/console.lua b/lua/structlog/sinks/console.lua index c423c86..4b62120 100644 --- a/lua/structlog/sinks/console.lua +++ b/lua/structlog/sinks/console.lua @@ -16,7 +16,7 @@ setmetatable(Console, { function Console:new(async) local console = { - async = async or true, + async = async, } Console.__index = Console diff --git a/test/unit/sinks/console_spec.lua b/test/unit/sinks/console_spec.lua new file mode 100644 index 0000000..ac3152a --- /dev/null +++ b/test/unit/sinks/console_spec.lua @@ -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)