Skip to content

feat(logging): structured slog logger with JSON/text output (#27)#67

Merged
Siddhant-K-code merged 1 commit into
mainfrom
feat/27-structured-logging
May 2, 2026
Merged

feat(logging): structured slog logger with JSON/text output (#27)#67
Siddhant-K-code merged 1 commit into
mainfrom
feat/27-structured-logging

Conversation

@Siddhant-K-code
Copy link
Copy Markdown
Owner

Closes #27

Summary

Adds pkg/logging — a thin wrapper around stdlib log/slog (Go 1.21+) with no external dependencies.

API

// JSON logger (production default)
logger := logging.New(logging.Config{Level: "info", Format: logging.FormatJSON})

// Text logger for local development
logger := logging.NewDebug()

// Attach request context
logger = logging.WithRequestID(logger, requestID)
logger = logging.WithTraceID(logger, traceID)
logger = logging.WithComponent(logger, "dedup")

Features

  • New(Config): configurable level (debug/info/warn/error) and format (json/text)
  • NewDefault(): JSON at info level to stderr
  • NewDebug(): text at debug level
  • WithRequestID / WithTraceID / WithComponent: child loggers with attached attributes
  • Unknown level strings default to info

Files

  • pkg/logging/logging.go
  • pkg/logging/logging_test.go — 11 tests

Implements issue #27. Adds pkg/logging with:
- New(Config): configurable level (debug/info/warn/error) and format (json/text)
- NewDefault(): JSON at info level to stderr
- NewDebug(): text at debug level for local development
- WithRequestID/WithTraceID/WithComponent: child loggers with attached attributes

Uses stdlib log/slog (Go 1.21+), no external dependencies.

Co-authored-by: Ona <no-reply@ona.com>
@Siddhant-K-code Siddhant-K-code added the enhancement New feature or request label May 2, 2026
@Siddhant-K-code Siddhant-K-code merged commit 903b339 into main May 2, 2026
1 of 2 checks passed
@Siddhant-K-code Siddhant-K-code deleted the feat/27-structured-logging branch May 2, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Structured JSON logging with debug mode

1 participant