src/ln: change formatter argument to a table with formatter

This commit is contained in:
Cadey Ratio 2019-12-25 18:37:02 +00:00
parent 2440dbc926
commit 3664cbb504
2 changed files with 61 additions and 52 deletions

View File

@ -59,4 +59,14 @@ describe("ln", function()
assert.truthy(string.find(msg, 'foo="bar with spaces"'))
end)
end)
describe("logger options", function()
local lgr = ln.Logger:new {
formatter = ln.LogfmtFormatter:new()
}
it("sets the formatter to non-nil", function()
assert.truthy(lgr.formatter)
end)
end)
end)

View File

@ -68,13 +68,12 @@ function Logger:log(...)
print(message)
end
function Logger:new(formatter)
if formatter == nil then
function Logger:new(o)
if o == nil then
o = {
formatter = LogfmtFormatter:new()
end
local o = {
formatter = formatter,
}
end
setmetatable(o, self)
self.__index = self
return o