The Logger class supports writing log messages into the server’s log file.
The log messages can be of the following severity: error, warn, info, debug, and trace.
The server’s log files are found inside the server’s logs
folder. By default “error”,
“warn”, and “info” messages go into the files “latest.log” and “debug.log”, while “debug” and
“trace” messages only go into “debug.log”.
The Logger class is a subtype of the Object class and inherits all its properties and functions.
Here is an overview of the Logger functions:
Function | Parameters | Results |
---|---|---|
debug | message, arg… | nil |
error | message, arg… | nil |
info | message, arg… | nil |
trace | message, arg… | nil |
warn | message, arg… | nil |
Below you find short descriptions about each of the functions and some examples about how to use them in your spells.
The ‘debug’ function writes the given debug message into the server’s log file if the log level is at least ‘debug’, prefixed with this logger’s name.
Optionally you can provide some message arguments that will be formatted into the final message (see string.format()).
Printing a debug message into the server’s log file, prefixed with the category label “my-logger”.
local logger = Loggers.get("my-logger")
logger:debug("Some debug message")
Printing a formatted debug message into the server’s log file, prefixed with the category label “my-logger.
local logger = Loggers.get("my-logger")
logger:debug("Some debug message with some value %s", value)
The ‘error’ function writes the given error message into the server’s log file if the log level is at least ‘error’, prefixed with this logger’s name.
Optionally you can provide some message arguments that will be formatted into the final message (see string.format()).
Printing an error message into the server’s log file, prefixed with the category label “my-logger”.
local logger = Loggers.get("my-logger")
logger:error("Some error message")
Printing a formatted error message into the server’s log file, prefixed with the category label “my-logger.
local logger = Loggers.get("my-logger")
logger:error("Some error message with some value %s", value)
The ‘info’ function writes the given information message into the server’s log file if the log level is at least ‘info’, prefixed with this logger’s name.
Optionally you can provide some message arguments that will be formatted into the final message (see string.format()).
Printing an info message into the server’s log file, prefixed with the category label “my-logger”.
local logger = Loggers.get("my-logger")
logger:info("Some info message")
Printing a formatted info message into the server’s log file, prefixed with the category label “my-logger.
local logger = Loggers.get("my-logger")
logger:info("Some info message with some value %s", value)
The ‘trace’ function writes the given tracing message into the server’s log file if the log level is at least ‘trace’, prefixed with this logger’s name.
Optionally you can provide some message arguments that will be formatted into the final message (see string.format()).
Printing a tracing message into the server’s log file, prefixed with the category label “my-logger”.
local logger = Loggers.get("my-logger")
logger:trace("Some tracing message")
Printing a formatted traceing message into the server’s log file, prefixed with the category label “my-logger.
local logger = Loggers.get("my-logger")
logger:trace("Some traceing message with some value %s", value)
The ‘warn’ function writes the given warning message into the server’s log file if the log level is at least ‘warn’, prefixed with this logger’s name.
Optionally you can provide some message arguments that will be formatted into the final message (see string.format()).
Printing a warning message into the server’s log file, prefixed with the category label “my-logger”.
local logger = Loggers.get("my-logger")
logger:warn("Some warning message")
Printing a formatted warning message into the server’s log file, prefixed with the category label “my-logger.
local logger = Loggers.get("my-logger")
logger:warn("Some warning message with some value %s", value)