Appearance
Log
The Log module provides a set of logging APIs for debugging purposes:
- A total of 3 log levels are supported:
INFO,WARN, andERR. - The file name and line number are captured with each log message.
- Logging to chat can be enabled via
Log.SetLoggingToChatEnabled()and includes colored severity levels. - A buffer of the most recent 200 log entries is kept for potential retrieval later (i.e. from an error handler).
Example
lua
-- Demo.lua
local MyModule = select(2, ...).MyModule
local Log = MyModule:From("LibTSMUtil"):Include("Util.Log")
Log.Info("My favorite number is %d", random(0, 100))
-- 12:15:24.615 [INFO] {Demo.lua:4} My favorite number is 42API
Inherits: LibTSMModule
Functions
Custom
lua
function Util.Log.Custom(severity, location, message, ...)Logs a formatted message with custom options.
Parameters:
| Name | Type | Description |
|---|---|---|
severity | LogSeverity | |
location | string | The location for the log message |
message | string | The message or format string |
... | string | number | boolean | The format arguments |
Err
lua
function Util.Log.Err(message, ...)Logs a formatted message at the error level.
Parameters:
| Name | Type | Description |
|---|---|---|
message | string | The message or format string |
... | string | number | boolean | The format arguments |
Get
lua
function Util.Log.Get(index)
-> "TRACE" | "INFO" | "WARN" | "ERR", string, string, stringGets a log entry from the log buffer.
Parameters:
| Name | Type | Description |
|---|---|---|
index | number | The index within the buffer |
Returns:
| Name | Type | Description |
|---|---|---|
severity | "TRACE" | "INFO" | "WARN" | "ERR" | |
location | string | |
timeStr | string | |
msg | string |
Info
lua
function Util.Log.Info(message, ...)Logs a formatted message at the info level.
Parameters:
| Name | Type | Description |
|---|---|---|
message | string | The message or format string |
... | string | number | boolean | The format arguments |
Length
lua
function Util.Log.Length()
-> numberGets the length of the log buffer.
Returns:
| Type | Description |
|---|---|
number |
LowerStackLevel
lua
function Util.Log.LowerStackLevel(amount)Lowers the stack level of log messages.
Parameters:
| Name | Type | Description |
|---|---|---|
amount | number | The amount to lower the stack level by (defaults to 1) |
PrepareFormatArgs
lua
function Util.Log.PrepareFormatArgs(...)
-> ...anyPrepares format args for logging.
Parameters:
| Name | Type | Description |
|---|---|---|
... | string | number | boolean | The format arguments |
Returns:
| Type | Description |
|---|---|
...any |
RaiseStackLevel
lua
function Util.Log.RaiseStackLevel(amount)Raises the stack level of log messages.
Parameters:
| Name | Type | Description |
|---|---|---|
amount | number | The amount to raise the stack level by (defaults to 1) |
SetCurrentThreadNameFunction
lua
function Util.Log.SetCurrentThreadNameFunction(func)Registers a function for getting the name of the current thread to include in log messages.
Parameters:
| Name | Type | Description |
|---|---|---|
func | fun(): string? | A function which returns the name of the currently-running thread |
SetLoggingToChatEnabled
lua
function Util.Log.SetLoggingToChatEnabled(enabled, ignoreBuffered)Enables or disables printing log messages to chat.
Parameters:
| Name | Type | Description |
|---|---|---|
enabled | boolean | The logging state to set |
ignoreBuffered | boolean | Ignore any buffered logs |
StackTrace
lua
function Util.Log.StackTrace(maxLines)Logs a stack trace.
Parameters:
| Name | Type | Description |
|---|---|---|
maxLines | number | The maximum number of lines (defaults to all available) |
Warn
lua
function Util.Log.Warn(message, ...)Logs a formatted message at the warning level.
Parameters:
| Name | Type | Description |
|---|---|---|
message | string | The message or format string |
... | string | number | boolean | The format arguments |