Packages
logger
Two preset slog loggers — readable text for development, structured JSON for production. Both write to stdout and plug into the standard library, so nothing in your code depends on bkgo.
Usage
import (
"log/slog"
"github.com/BounkhongDev/bkgo/logger"
)
// cmd/api/main.go — pick one based on the environment
log := logger.Development() // debug level, human-readable text
if cfg.App.Env == "production" {
log = logger.Production() // info level, structured JSON
}
slog.SetDefault(log)
// Anywhere else — just use the stdlib
slog.Info("user created", "user_id", user.ID)
slog.Error("payment failed", "err", err, "order_id", id)After slog.SetDefault(log), the rest of your code calls slog.Info / slog.Error directly — no bkgo import needed outside main.go. Writes to stdout, so your platform's log collector picks it up unchanged.
Presets
| Preset | Level | Format |
|---|---|---|
logger.Development() | slog.LevelDebug | text |
logger.Production() | slog.LevelInfo | json |
Output
# logger.Development() — text, debug and up
time=2026-01-15T10:23:44.001+07:00 level=INFO msg="user created" user_id=8f2c
# logger.Production() — JSON, info and up
{"time":"2026-01-15T10:23:44.001+07:00","level":"INFO","msg":"user created","user_id":"8f2c"}Custom level and format
// Full control over level and format
log := logger.New(logger.Options{
Level: slog.LevelWarn,
Format: logger.FormatJSON,
})API
type Format string
const (
FormatText Format = "text"
FormatJSON Format = "json"
)
type Options struct {
Level slog.Level
Format Format
}
func New(opts Options) *slog.Logger
// Development returns a debug-level text logger.
func Development() *slog.Logger
// Production returns an info-level JSON logger.
func Production() *slog.Logger