mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
feat(print): add convar change listener (#728)
This commit is contained in:
@@ -14,8 +14,12 @@ local levelPrefixes = {
|
||||
'^4[VERBOSE]',
|
||||
'^6[DEBUG]',
|
||||
}
|
||||
|
||||
local resourcePrintLevel = printLevel[GetConvar('ox:printlevel:' .. cache.resource, GetConvar('ox:printlevel', 'info'))]
|
||||
local convarGlobal = 'ox:printlevel'
|
||||
local convarResource = 'ox:printlevel:' .. cache.resource
|
||||
local function getPrintLevelFromConvar()
|
||||
return printLevel[GetConvar(convarResource, GetConvar(convarGlobal, 'info'))]
|
||||
end
|
||||
local resourcePrintLevel = getPrintLevelFromConvar()
|
||||
local template = ('^5[%s] %%s %%s^7'):format(cache.resource)
|
||||
local function handleException(reason, value)
|
||||
if type(value) == 'function' then return tostring(value) end
|
||||
@@ -48,4 +52,14 @@ lib.print = {
|
||||
debug = function(...) libPrint(printLevel.debug, ...) end,
|
||||
}
|
||||
|
||||
-- Update the print level when the convar changes
|
||||
if (AddConvarChangeListener) then
|
||||
AddConvarChangeListener('ox:printlevel*', function(convarName, reserved)
|
||||
if (convarName ~= convarResource and convarName ~= convarGlobal) then return end
|
||||
resourcePrintLevel = getPrintLevelFromConvar()
|
||||
end)
|
||||
else
|
||||
libPrint(printLevel.verbose, 'Convar change listener not available, print level will not update dynamically.')
|
||||
end
|
||||
|
||||
return lib.print
|
||||
|
||||
Reference in New Issue
Block a user