small logger for brightscript which can calculate indentation for current call's stack
Check out output
and components/SceneRoot.brs
files to see more examle of usage.
We cannot automatically update call stack after functions executions because there is no way to have destructors aka in c++. But we can detect whether the logged function is executed or not. I would name it as lazy destructors :D
Just copy /source/utilities/FuncLogger.brs
file to your project and add script for needed component.
Or you can copy code from file above to you utility file.
Just call logFunc("name of some function")
and save returned value as local variable (see example).
Example:
sub basicUsage()
_ = logfunc("basicUsage") ' or funclogger().logFunc("basicUsage")
_.p("print from basicUsage")
_.xp("nobody will se me") ' won't be printed
basicNested_1()
foo_log()
end sub
sub basicNested_1()
_ = logfunc("basicNested_1")
_.p("print from basicNested_1 - {0} {1}", "it", "works")
foo_log()
ignored_foo_log()
end sub
sub foo_log()
_ = logfunc("foo_log")
_.p("print from foo_log")
end sub
sub ignored_foo_log()
_ = xlogfunc("it won't be printed")
_.p("this one also")
_.xp("this too")
end sub
Output:
--> SceneRoot::basicUsage
print from basicUsage
--> SceneRoot::basicNested_1
print from basicNested_1 - it works
--> SceneRoot::foo_log
print from foo_log
--> SceneRoot::foo_log
print from foo_log
Returns instance of FuncLogger
. Also each call funcLogger()
will update and save current call stack.
Makes log with passed function name.
Same as funcLogger().logFunc("function name")
Parameters:
funcName as string
- name of function that will be logged
Return value:
- function tracker object that has interface for work with created log
Use it for skip particular log
Will permanently lock funcLogger for current component.
All calls to logFunc
will be ignored.
Will permanently unlock funcLogger for current component.
Will convert any variable to string if it possible
Parameters:
- obj - object that will be converted to string
- _tab - (oprional) which indentation should be applied for converted object
Possible values:
"none"
- relatime output."full"
- will cache all logs."short"
- will cache logs only for current call stack. Each time when stack size reaches 0, logs will be cleared.
Aka how many whitespaces use for tab.
Set as true
to disable FuncLogger
If true
will print component type (m.top.subtype()
).
If true
will print component id.
If true
will print name of parent function
If true
will print time when function was called.
With next format minutes:seconds.milliseconds
If true
will print execution time of function.
NOTE: it is inaccurate, and requires additional call funcLogger()
after function executes.
Returns current offset according to call's stack
Will permanently disable/enable funcLogger
Makes print that will be printed/cahced with correct indentation
Parameters:
ignoreIndentation = false
- optional, determines whethertext
will be printed with current indentation
Makes formatted print and call m.log
under hood.
Parameters:
text
- string that will be formatted and passed tom.log
args = []
- an array of args that will be used for substitution intext
ignoreIndentation = false
- optional, determines whethertext
will be printed with current indentation
Will print out all cached logs
Makes log with passed function name.
Same as global logFunc("function name")
Parameters:
funcName as string
- name of function that will be logged
Return value:
- function tracker object that has interface for work with created log
Use it for skip particular log
Will update current state of global field, where we store state
Formatted log print will be printed/cahced with correct indentation for current function log.
Skipped print
Will mute all prints for current function
Will mute prints in all nested functions
Will mute all prints for current function and nested functions
Will temporarily lock funcLogger for nested functions. Unlocks after function executes
Will permanently lock funcLogger for current component.
Same as lockcomponent()
Will temporarily lock funcLogger for current component. Unlocks after function executes