mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +00:00
- Introduced a new `isTraceEnabled` function in the logging module to check if trace logging is enabled based on the current log level. - Updated the `performRequest` function to only log HTTP request details and responses if trace logging is enabled, reducing unnecessary log output and improving performance. These changes aim to enhance the efficiency of logging during HTTP requests by avoiding excessive logging when not needed.
64 lines
1.1 KiB
Lua
64 lines
1.1 KiB
Lua
local Fmt = require(script.Parent.Fmt)
|
|
|
|
local Level = {
|
|
Error = 0,
|
|
Warning = 1,
|
|
Info = 2,
|
|
Debug = 3,
|
|
Trace = 4,
|
|
}
|
|
|
|
local function getLogLevel()
|
|
return Level.Info
|
|
end
|
|
|
|
local function addTags(tag, message)
|
|
return tag .. message
|
|
end
|
|
|
|
local TRACE_TAG = "[Rojo-Trace] "
|
|
local INFO_TAG = "[Rojo-Info] "
|
|
local DEBUG_TAG = "[Rojo-Debug] "
|
|
local WARN_TAG = "[Rojo-Warn] "
|
|
|
|
local Log = {}
|
|
|
|
Log.Level = Level
|
|
|
|
function Log.setLogLevelThunk(thunk)
|
|
getLogLevel = thunk
|
|
end
|
|
|
|
function Log.isTraceEnabled()
|
|
return getLogLevel() >= Level.Trace
|
|
end
|
|
|
|
function Log.trace(template, ...)
|
|
if getLogLevel() >= Level.Trace then
|
|
print(addTags(TRACE_TAG, Fmt.fmt(template, ...)))
|
|
end
|
|
end
|
|
|
|
function Log.info(template, ...)
|
|
if getLogLevel() >= Level.Info then
|
|
print(addTags(INFO_TAG, Fmt.fmt(template, ...)))
|
|
end
|
|
end
|
|
|
|
function Log.debug(template, ...)
|
|
if getLogLevel() >= Level.Debug then
|
|
print(addTags(DEBUG_TAG, Fmt.fmt(template, ...)))
|
|
end
|
|
end
|
|
|
|
function Log.warn(template, ...)
|
|
if getLogLevel() >= Level.Warning then
|
|
warn(addTags(WARN_TAG, Fmt.fmt(template, ...)))
|
|
end
|
|
end
|
|
|
|
function Log.error(template, ...)
|
|
error(Fmt.fmt(template, ...))
|
|
end
|
|
|
|
return Log
|