| name | golem-logging-moonbit |
| description | Adding logging to a MoonBit Golem agent. Use when the user asks about logging, log messages, log levels, wasi:logging, @logging, or printing debug/info/error output from a MoonBit agent. |
Logging from a MoonBit Agent
The MoonBit SDK provides a high-level @logging module (from golemcloud/golem_sdk/logging) built on top of wasi:logging/logging. It supports named loggers, log levels, and global level filtering.
Quick Start
The @logging package is already imported in the template moon.pkg. Use the module-level convenience functions:
@logging.info("order created: " + order_id)
@logging.debug("processing item: " + item_id)
@logging.warn("retry attempt " + attempt.to_string())
@logging.error("failed to connect: " + err)
Using a Named Logger
Create a logger with a context name for structured, scoped output. The context string is passed as the WASI context parameter:
let logger : @logging.Logger = @logging.with_name("order-service")
fn process_order(self : Self, order_id : String) -> Unit {
logger.info("processing order: " + order_id)
logger.debug("validating items")
}
Loggers are immutable values — with_name appends a /-separated segment to the context:
let db_logger = logger.with_name("database")
// context is "order-service/database"
db_logger.info("connected to database")
Log Levels
| Function | WASI Level | Use for |
|---|
@logging.trace(...) / logger.trace(...) |