Skip to content

feat(logging): Migrate to Go structured logging with slog #970

Description

@Princess0407

Description

urunc currently uses standard Go logging (log package or fmt.Printf) throughout the codebase. This produces unstructured, plain-text logs that are difficult to filter, query, or aggregate in production deployments.

Go 1.21 introduced log/slog, the standard structured logging package. Migrating to slog would enable leveled logging (Debug, Info, Warn, Error), structured key-value pairs, and JSON output.... all without external dependencies.

Proposed Work

  1. Introduce a centralized logger in pkg/ or internal/ using log/slog.
  2. Replace log.Printf / fmt.Printf logging calls with slog.Info, slog.Debug, slog.Error across:
    • pkg/unikontainers/ (VM lifecycle, network, initrd)
    • pkg/containerd-shim/ (shim operations)
    • cmd/urunc/ (CLI commands)
  3. Add a --log-format flag to urunc CLI supporting text (default) and json.
  4. Add a --log-level flag supporting debug, info, warn, error.

Why This Matters

  • Structured logs enable filtering and aggregation in production (e.g., "show all ERROR logs from network setup").
  • JSON output integrates with log aggregation systems (ELK, Loki, CloudWatch).
  • Aligns with modern Go practices (runc, containerd both use structured logging).
  • Zero external dependencies slog is in the standard library.

Acceptance Criteria

  • slog logger is initialized at program startup with configurable level/format.
  • All existing log calls migrated to structured equivalents.
  • urunc --log-level=debug --log-format=json produces valid JSON logs.
  • No functional behavior changes purely logging migration.

Non-Priorities

  • Adding new logging frameworks (zap, zerolog, etc.)slog only.
  • Changing error handling logic.
  • Adding new features beyond logging.

I can start with pkg/unikontainers/ and then move on from there...

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions