File SMLogger.mys
Logging utility, prints informations or error to console and log file.
You can choose the levels to print, i.e. only warnings and errors and ignore infos and debug.
By default, the level is set to info or debug if you run the script from the menu or the editor.
Two stacking function help to understand the context when an error happen.
SMLogger.mys is automatically included when you Include "SMUtils"
.
Section
Section | Summary |
---|---|
Debug | Debugg and log functions. |
Summary
Constant | Type | Summary |
---|---|---|
LOG_FILE | string | Output logs in a file? |
LOG_LEVEL | int | Logging level for your script. |
LOG_LEVEL_DEBUG | int | Logging level: debug |
LOG_LEVEL_ERROR | int | Logging level: error |
LOG_LEVEL_INFO | int | Logging level: info |
LOG_LEVEL_TRACE | int | Logging level: trace, a more detailled debug |
LOG_LEVEL_WARN | int | Logging level: warning |
Return type | Function and summary |
---|---|
SMProfilerStart() Start a profiler, to help you optimize your code. | |
Map | SMProfilerStop(boolean printStats) Stop the profiler, and prints the stats on the console. |
SMStack(string funcName) Add function name in the stack trace. | |
SMUnstack(string funcName) Remove function name from the stack trace. | |
debug(...) Log debugging informations. | |
err(...) Log error This print "ERROR "..text to the console. | |
info(...) Log informations. | |
printStackTrace(int size) Prints the stack trace to the console | |
trace(...) Log trace-debugging informations. | |
warn(...) Log warning This print "WARN "..text to the console. |
Constants
string LOG_FILE
Output logs in a file?
Set LOG_FILE to a filename if you want so. Log lines older than 30 days are automatically deleted to avoid endless growth of the file.
int LOG_LEVEL_TRACE
Logging level: trace, a more detailled debug
int LOG_LEVEL_DEBUG
Logging level: debug
int LOG_LEVEL_INFO
Logging level: info
int LOG_LEVEL_WARN
Logging level: warning
int LOG_LEVEL_ERROR
Logging level: error
int LOG_LEVEL
Logging level for your script.
By default, it's set to LOG_LEVEL_DEBUG if run from the script editor, in debug mode, and LOG_LEVEL_INFO if run from the menu.
Functions
trace(...)
Log trace-debugging informations.
This allow you to keep logging in your script, even if shared with Myriad community.
This print "TRACE "..text
to the console.
If you often use print and comment all these prints before sharing, this will save you time!
Parameter | Type | Default | Description |
---|---|---|---|
... | ... |
debug(...)
Log debugging informations.
This allow you to keep logging in your script, even if shared with Myriad community.
By default, debugs will appear on console when script is run in debug mode, and hidden if run directly from the menu.
This print "DEBUG "..text
to the console.
If you often use print and comment all these prints before sharing, this will save you time!
Parameter | Type | Default | Description |
---|---|---|---|
... | ... |
info(...)
Log informations.
This print "INFO "..text
to the console.
Parameter | Type | Default | Description |
---|---|---|---|
... | ... |
warn(...)
Log warning This print "WARN "..text
to the console.
Parameter | Type | Default | Description |
---|---|---|---|
... | ... |
err(...)
Log error This print "ERROR "..text
to the console.
Parameter | Type | Default | Description |
---|---|---|---|
... | ... |
- See
- throw
SMProfilerStart()
Start a profiler, to help you optimize your code.
This count functions calls and watch the spent time for each call.
The profiler also consume a bit of time and memory, so use it only when you are concerned by execution time of your script. Never publish a script with profiler enabled!
Once your code is optimized, remove the calls to SMProfilerStart and stop.
- See
- SMProfilerStop for printing results.
SMProfilerStop(boolean printStats)
Stop the profiler, and prints the stats on the console.
Parameter | Type | Default | Description |
---|---|---|---|
printStats | boolean | true |
- Return
- Map: Map of function name (key), to table values. Structure of the table may varies, so it's highly recommand to let the printStats to it's default value.
SMStack(string funcName)
Add function name in the stack trace.
Stack trace is printed in the console in case of assertion fail or throw that stop the script.
Lua errors (syntax, divide by zero, out of memory) can't display the stack.
Don't forget to remove it before the return or end of the function using SMUnstack.
This function tries to alert (warning messag ein console) if stack overflow may occur shortly. If so, it prints the stack trace.
Parameter | Type | Default | Description |
---|---|---|---|
funcName | string | funcName |
- See
- SMUnstack
SMUnstack(string funcName)
Remove function name from the stack trace.
Parameter | Type | Default | Description |
---|---|---|---|
funcName | string | funcName |
- See
- SMStack
printStackTrace(int size)
Prints the stack trace to the console
Parameter | Type | Default | Description |
---|---|---|---|
size | int | 15 | Max number of lines to print |