--[[
    SMALL SHARED LOGGER

    Keeping one prefix and one-line messages makes BagLootFramework problems
    easy to find in UE4SS.log. Control characters are removed so a malformed
    configuration value cannot make the log misleading or unreadable.
]]

local Logger = {}

local PREFIX = "[BagLootFramework] "


local function clean(message)
    local text = tostring(message)

    text = text:gsub("[\r\n\t]+", " ")
    text = text:gsub("%c", "?")
    text = text .. "\n"
    return text
end


local function write(label, message)
    local heading = label and (label .. ": ") or ""
    print(PREFIX .. heading .. clean(message))
end


function Logger.Info(message)
    write(nil, message)
end


function Logger.Warning(scope, message)
    write(tostring(scope) .. " WARNING", message)
end


function Logger.Error(scope, message)
    write(tostring(scope) .. " ERROR", message)
end


return Logger
