A LuaRocks-packaged logging library for Mudlet.
Provides leveled logging for Mudlet packages.
Mudlet is a free, open-source, cross-platform client for playing and scripting MUDs (Multi-User Dungeons).
This logger is designed for use in Mudlet packages. It depends on several Mudlet-specific APIs and global functions, and does not work in a generic Lua environment.
Required Mudlet APIs and globals:
debugccechoprintDebuggetMudletHomeDirNote:
Usage outside your package code, such as in global scripts or the Mudlet editor, is discouraged and, in any case, depends on your LuaRocks integration layer.
luarocks install toasted_mudlet_logger
Or, if using a custom tree:
luarocks install --tree=lua_modules toasted_mudlet_logger
Then build your Mudlet package as usual.
After installing, require the logger in your Mudlet package code:
local logger = require("toasted_mudlet_logger")
logger.info("Logger initialized!")
logger.warn("This is a warning message.")
logger.error("This is an error message.")
logger.debug("Debugging details here.")
You can control which log messages are shown by setting the global log level.
Valid levels are "DEBUG", "INFO", "WARN", and "ERROR" (case-sensitive):
logger.setGlobalLogLevel("INFO")
This will suppress all DEBUG messages and show only INFO, WARN,
and ERROR messages.
By default, logs are sent to the Mudlet error console.
To also log to the main game console, enable this with:
logger.setLogToMain(true)
You can turn this off again with:
logger.setLogToMain(false)
If you run tests outside the Mudlet runtime (for example,
in CI or a generic Lua environment), you can replace the real logger with the
provided FakeLogger. The FakeLogger implements the same interface as the
real logger but does nothing, preventing errors caused by missing Mudlet
functions.
Example (in your test setup):
-- Override the logger module before requiring your code under test
package.loaded["toasted_mudlet_logger.Logger"] = require("toasted_mudlet_logger.FakeLogger")
local myModule = require("my_module_that_uses_logger")
-- Now, calling logger methods will not fail outside Mudlet
myModule.doSomethingThatLogs()
This approach is useful for running automated tests or scripts in environments where Mudlet”s APIs are not available.
If you create a new project based substantially on this logger, please consider adding the following attribution or similar for all derived code:
This project is based on Toasted Mudlet Logger, originally licensed under the MIT License (see LICENSE for details). All original code and documentation remain under the MIT License.
Copyright © 2025 github.com/toasted323
This project is licensed under the MIT License.
See LICENSE in the root of this repository for full details.