[cmd] Logger - Strooth mod
stableDescription
Logger from Pshai, recreated as a custom command to drop into any script, without taking up to much visual script space and should then get threading speed improvements (happy to be corrected here).
Has three parameters - name so you can define if using it more than once to create seperate log identifiers and the ability to enable disable and set level via script input or normal input. Also using list to string command which is required and modded in, it should output any list or array without a drama no matter how deep and staggered the tree goes basically.
To use it in a script - at the head of the script load it into a variable like so
local Logger = CC_Logger()
then to use
Logger.Log('something i need to log')
Note requires my custom command [cmd] ListToString
-- Author - Strooth - Find me on discord - strooth#4739
-- Feel free to donate to support my work or if my script helped you in any way <3
-- BTC Adress: 33MsEAbA8tg7SpohgnCpSrmPTBih2UkhxQ
--
HaasScript
--Author: Pshai - Modded by Strooth - Find me on discord - strooth#4739
-- Feel free to donate to support my work or if my script helped you in any way <3
-- BTC Adress: 33MsEAbA8tg7SpohgnCpSrmPTBih2UkhxQ
--
DefineCommand("Logger", "Advanced Logger - Logger = CC_Logger(); Logger.log('your log message')")
local name = DefineParameter(StringType, 'name', 'the unique name if using more then one logger', false, '', 'string/text')
local level, where, enter, exit, log, warn, error
local LoggerLevels = {
ErrorsOnly = 'Errors Only',
ErrorsAndWarnings = 'Erorrs & Warnings',
All = 'All'
}
local _verbose = DefineParameter(BooleanType, 'enable', 'Debug enable', false, Input(' '..name..' DEBUG Enable', false, {group = name..' DEBUG'}), 'true/false')
local _level = DefineParameter(StringType, 'level', 'the debug level', false, InputOptions(' '..name..' DEBUG Level',
LoggerLevels.All,
LoggerLevels,
{group = name..' DEBUG'}),
'string/text')
local _in = 'Main'
local _prevIn = {}
local _log = Log
local _warn = LogWarning
local _error = LogError
function level()
if _level == LoggerLevels.ErrorsOnly then
return 0
elseif _level == LoggerLevels.ErrorsAndWarnings then
return 1
elseif _level == LoggerLevels.All then
return 2
else
return 0
end
LogError(' '..name..' Logger level undefined: "' .. _level .. '"')
end
function where()
local ret = ''
local prevs = _prevIn
if #prevs > 0 then
for i = 1, #prevs do
if prevs[i] != '' and #prevs[i] > 0 then
ret = ret .. prevs[i] .. '::'
end
end
end
return ret .. _in
end
function enter(msg)
if _verbose and IfNull(msg, false) then
_prevIn = ArrayAdd(_prevIn, _in)
_in = Parse(CC_ListToString(msg), StringType)
end
end
function exit()
if _verbose then
if Count(_prevIn) > 0 then
_in = ArrayLast(_prevIn)
_prevIn = ArrayPop(_prevIn)
end
end
end
function log(msg, color)
if _verbose and IfNull(msg, false) then
if level() >= 2 then
local _in = where()
_log(Parse(StringJoin('['..name..' '.._in..'] ', CC_ListToString(msg)), StringType), color)
end
end
end
function warn(msg)
if _verbose and IfNull(msg, false) then
if level() >= 1 then
local _in = where()
_warn(Parse(StringJoin('['..name..' '.._in..'] ', CC_ListToString(msg)), StringType))
end
end
end
function error(msg)
if _verbose and IfNull(msg, false) then
local _in = where()
_error(Parse(StringJoin('['..name..' '.._in..'] ', CC_ListToString(msg)), StringType))
end
end
DefineOutput(ListDynamicType, {log = log, enter = enter, exit = exit, warn = warn, error = error}, 'Logger = CC_Logger()', "list")
DefineOutputIndex(1, DynamicType, "log", "Logger = CC_Logger(); Logger.log('your log message', Green)", "ListDynamicType")
DefineOutputIndex(2, DynamicType, "enter", "Logger = CC_Logger(); Logger.enter('name')", "ListDynamicType")
DefineOutputIndex(3, DynamicType, "exit", "Logger = CC_Logger(); Logger.exit()", "ListDynamicType")
DefineOutputIndex(4, DynamicType, "warn", "Logger = CC_Logger(); Logger.warn('your log message')", "ListDynamicType")
DefineOutputIndex(5, DynamicType, "error", "Logger = CC_Logger(); Logger.error('your log message')", "ListDynamicType")
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!