[CMD]DebugLogger
stableDescription
A handy logging cmd to use lists and headings, with both normal and warning logs together. Used some of Firetrons logging in his DCA dipper and transformed it into this.
Example from the Autorisk Management Command below
Sections are (logging, heading, normallog, warninglog, verbose)
Both normallog and warninglog parameters can be lists
CC_DebugLogger(Logging, nil, {Parse('Dynamic Max Open: '..Round(maxCheck, 5)..' '..AmountLabel(), StringType)}, nil, Verbose)
HaasScript
-- ============================================================================
-- Strooths Debug Logger
--
--
-- Custom Command Dependencies:
-- None
--
-- ============================================================================
-- ========================================================
-- Variables
-- ========================================================
local logHRule = '-- ========================================================';
local string = ''
-- ------------------------------------
-- Parameter
-- ------------------------------------
local name
local description
local type
local isRequired
local defaultValue
local inputSuggestions
local outputSuggestions
local Heading
local Normal
local Warning
local Verbose
local Trigger
-- ========================================================
-- Command Definition
-- ========================================================
name = 'DebugLogger'
description = 'Custom Debug Logging'
DefineCommand(name, description)
-- ========================================================
-- Parameter Definition
-- ========================================================
type = BooleanType
name = 'Trigger'
description = 'The true/false trigger to enable this command to run'
isRequired = true
defaultValue = false
inputSuggestions = 'true or false'
Trigger = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
type = StringType
name = 'Heading'
description = 'The number of positions to create.'
isRequired = false
defaultValue = ''
inputSuggestions = 'Debug Logging'
Heading = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
type = ListDynamicType
name = 'Normal'
description = 'A list of things to log in plain text.'
isRequired = false
defaultValue = ''
inputSuggestions = 'List of Log Data'
Normal = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
type = ListDynamicType
name = 'Warning'
description = 'A list of things to log in with coloured text.'
isRequired = false
defaultValue = ''
inputSuggestions = 'List of Log Data'
Warning = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
type = BooleanType
name = 'Verbose'
description = 'Additional Verbose Logging'
isRequired = false
defaultValue = false
inputSuggestions = 'true or false'
Verbose = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
-- ========================================================
-- Functions
-- ========================================================
local ResetSafeLog = function()
Save('lastLog', '')
end
-- ----------------
local SafeLog = function(text)
if text == Load('lastLog', '') then return end
Log(text)
Save('lastLog', text)
end
-- ----------------
local SafeLogWarning = function(text)
if text == Load('lastLog', '') then return end
LogWarning(text)
Save('lastLog', text)
end
-- ========================================================
-- Execution
-- ========================================================
if Verbose then ResetSafeLog() end
if Trigger then
SafeLog(logHRule)
local wt = GetType(Warning)
local nt = GetType(Normal)
if Warning and wt == ArrayDataType then
for i = #Warning, 1, -1 do
SafeLogWarning(Warning[i])
end
elseif wt == TextDataType and string.len(Warning) >= 1 then
SafeLogWarning(Warning)
end
if Normal and nt == ArrayDataType then
for i = #Normal, 1, -1 do
SafeLog(Normal[i])
end
elseif nt == TextDataType and string.len(Normal) >= 1 then
SafeLog(Normal)
end
if Heading and string.len(Heading) >= 1 then
SafeLog(logHRule)
Heading = StringJoin('!***** ', Heading)
Heading = StringJoin(Heading,' *****!')
SafeLog(Heading)
SafeLog(logHRule)
end
SafeLog(logHRule)
end
-- ========================================================
-- Output Definitions
-- ========================================================
DefineOutput(VoidType)
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!