OKHAM.org Documentación EnglishCastellano

Edición publicada en febrero de 2026

Documento original en inglés

Logging Specification

Disclaimer: This document is non-normative and describes recommended practices for the OKHAM ecosystem.

Version 1.0.0

Status: DRAFT

This document specifies the canonical logging requirements for all OKHAM capabilities.


Canonical Logger Requirement

All OKHAM capabilities MUST use the canonical logger provided by the capability runtime.

Forbidden Patterns:

Standard Library Logging

// FORBIDDEN
import "log"

log.Println("message")
log.Printf("value: %d", x)
log.Fatal("error")

Third-Party Logging Libraries

// FORBIDDEN
import "github.com/sirupsen/logrus"
import "go.uber.org/zap"

logrus.Info("message")
zap.S().Infof("message: %s", msg)

Correct Pattern

// REQUIRED - Use RuntimeContext logger
func (s *Service) HandleRequest(ctx context.Context, req Request) error {
    s.rt.Logger.Info("handling request",
        rt.F.Str("request_id", req.ID),
        rt.F.Int("attempt", attempt),
    )
}

Structured Logging

All logs MUST include context via structured fields:

// REQUIRED
rt.Logger.Info("camera registered",
    rt.F.Str("camera_id", camera.ID),
    rt.F.Str("model", camera.Model),
    rt.F.Str("location", camera.Location),
    rt.F.Time("registered_at", time.Now()),
)

// For errors
rt.Logger.Error("failed to process message",
    rt.F.Str("subject", msg.Subject),
    rt.F.Err(err),
)

Field Builder Reference

Field Type Method Example
String rt.F.Str(key, value) rt.F.Str("id", "cam-01")
Int rt.F.Int(key, value) rt.F.Int("count", 42)
Bool rt.F.Bool(key, value) rt.F.Bool("active", true)
Error rt.F.Err(err) rt.F.Err(err)
Any rt.F.Any(key, value) rt.F.Any("data", data)

Log Level Usage

Level Usage
DEBUG Detailed debugging info, only in development
INFO Normal operational events
WARN Recoverable issues, degraded functionality
ERROR Failed operations, requires attention