Unify logging

This commit is contained in:
Lucien Greathouse
2018-12-03 16:24:28 -08:00
parent dd4d542d7e
commit 061ea0e7a3
6 changed files with 70 additions and 42 deletions

View File

@@ -1,21 +1,49 @@
local enabledByTest = false
local testLogLevel = nil
local configValue = game:FindFirstChild("ROJO_LOG")
local function isEnabled()
return _G.ROJO_LOG or enabledByTest
local Level = {
Error = 0,
Warning = 1,
Info = 2,
Trace = 3,
}
local function getLogLevel()
if testLogLevel ~= nil then
return testLogLevel
end
if _G.ROJO_LOG ~= nil then
return _G.ROJO_LOG
end
if configValue ~= nil then
return configValue.Value
end
return Level.Info
end
local Logging = {}
local Log = {}
function Logging.info(template, ...)
if isEnabled() then
print("[Rojo] " .. template:format(...))
Log.Level = Level
function Log.trace(template, ...)
if getLogLevel() >= Level.Trace then
print("[Rojo-Trace] " .. string.format(template, ...))
end
end
function Logging.warn(template, ...)
if isEnabled() then
warn("[Rojo] " .. template:format(...))
function Log.info(template, ...)
if getLogLevel() >= Level.Info then
print("[Rojo-Info] " .. string.format(template, ...))
end
end
return Logging
function Log.warn(template, ...)
if getLogLevel() >= Level.Warning then
warn("[Rojo-Warn] " .. string.format(template, ...))
end
end
return Log