---@alias LogLevel string
---@alias GroupAction integer

---@class LogEntry
---@field timestamp string
---@field thread_id number
---@field level LogLevel
---@field message string
---@field controller string

---@class GroupActions
---@field create fun(level:integer):GroupAction
---@field accumulate GroupAction

---@class LogLevels
---@field trace LogLevel
---@field debug LogLevel
---@field info LogLevel
---@field warn LogLevel
---@field error LogLevel

---@class XLogger
---@field filter fun(log_entry:LogEntry):boolean
---@field grouper fun(log_entry:LogEntry):GroupAction
---@field config table

---@type LogLevels
---@diagnostic disable-next-line:lowercase-global
log_levels = log_levels or {}

---@type GroupActions
---@diagnostic disable-next-line:lowercase-global
group_actions = group_actions or {}

---@type XLogger
---@diagnostic disable-next-line:lowercase-global
xlogger = xlogger or {}

xlogger.grouper = function(entry)
    if entry.level == log_levels.error then
        if entry.message:find('Cannot acquire item') then
            return group_actions.create(2)
        else
            return group_actions.create(1)
        end
    end
    return group_actions.accumulate
end

xlogger.filter = function(entry)
    if entry.level == log_levels.info then
        return false
    end
    return true
end
