Standard Library
Logging

Logging Module

The log module provides structured logging with multiple log levels.

Log Levels

log.info()

log.info("Application started");
log.info("User logged in");

log.warn()

log.warn("Memory usage high");
log.warn("API rate limit approaching");

log.error()

log.error("Database connection failed");
log.error("Invalid configuration");

log.debug()

log.debug("Processing request");
log.debug("Variable value: " + tostring(x));

Examples

Application Logging

func start_application() {
    log.info("Starting application");
    log.debug("Loading configuration");
    
    let db = sqlite.open("app.db");
    if (db != null) {
        log.info("Database connected");
    } else {
        log.error("Database connection failed");
        return;
    }
    
    log.info("Application ready");
}

Request Logging

func handle_request(req, res) {
    log.info("Request: " + req.method + " " + req.path);
    
    // Process request
    
    log.info("Response: 200 OK");
}

Error Tracking

func process_data(data) {
    if (data == null) {
        log.error("Invalid data: null");
        return false;
    }
    
    if (type(data) != "hash") {
        log.error("Invalid data type: " + type(data));
        return false;
    }
    
    log.debug("Processing data: " + json.stringify(data));
    return true;
}

Best Practices

  • Use appropriate log levels
  • Include context in log messages
  • Don't log sensitive data (passwords, tokens)
  • Log errors with details
  • Use debug logs for troubleshooting

Next Steps