skills/go-logging/SKILL.md
Use when adding or configuring structured logging in Go projects, integrating zap-based log with request context, or when the user asks about logging. Places log package under pkg/logs for new projects.
npx skillsauth add hicker-kin/ai-context go-loggingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Structured logging using zap with console/file output, rotation, and request context.
| Project Type | Path / Lookup order |
|--------------|---------------------|
| New project | pkg/logs/ |
| Existing project | 1) pkg/log 2) pkg/logs 3) pkg/utils/log/ (fallback) |
For new projects, MUST create the log package under pkg/logs/.
For existing projects, use the first found among pkg/log, pkg/logs; only use pkg/utils/log/ when neither exists.
go.uber.org/zapgithub.com/natefinch/lumberjack (for file rotation)WithRequestID: a request package that provides GetRequestID(ctx) and REQUEST_ID_KEY; new projects may implement a simple version using context.Value with a custom key.type Config struct {
Console bool // console output
AddSource bool // caller info
Level string // debug, info, warn, error, fatal
Format string // json | text
Rotate OutFile
}
type OutFile struct {
Enabled bool
OutputPath string
MaxSize int // MB
MaxAge int // days
MaxBackups int
Compress bool
LocalTime bool
}
When OutFile.Enabled and Console are both true, output MUST go to both disk and console. Use zapcore.NewMultiWriteSyncer to combine writers:
var mws []zapcore.WriteSyncer
if c.Rotate.Enabled {
rotateCfg := &lumberjack.Logger{
Filename: fn,
MaxSize: c.Rotate.MaxSize,
MaxAge: c.Rotate.MaxAge,
MaxBackups: c.Rotate.MaxBackups,
Compress: c.Rotate.Compress,
LocalTime: c.Rotate.LocalTime,
}
mws = append(mws, zapcore.AddSync(rotateCfg))
}
if c.Console {
mws = append(mws, zapcore.AddSync(os.Stdout))
}
mw := zapcore.NewMultiWriteSyncer(mws...)
core := zapcore.NewCore(encoder, mw, level)
Call from main or server bootstrap:
log.Init(log.Config{
Console: true,
AddSource: true,
Level: "info",
Format: "json",
Rotate: log.OutFile{
Enabled: true,
OutputPath: "./logs", // or pkg/logs relative path
MaxSize: 100,
MaxAge: 7,
MaxBackups: 3,
},
})
| Function | Purpose |
|----------|---------|
| log.Init(c Config) | Initialize logger (call once at startup) |
| log.Logger() *zap.Logger | Get global logger; returns default console if not initialized |
| log.WithRequestID(ctx, l) *zap.Logger | Attach request_id from context to logger |
| log.Debug/Info/Warn/Error(msg, fields...) | Package-level logging |
NewService(..., logger *zap.Logger).WithRequestID(ctx, logger) at the start of request-scoped methods.zap.Error(err), zap.String(), zap.Any(), zap.Int().| Level | When | |-------|------| | Debug | Development/troubleshooting | | Info | Normal flow, key operations | | Warn | Validation failure, retry | | Error | Operation failure, before return err |
For full usage examples, see examples.md.
development
Guides Go development to follow project architecture and code style rules. Use when implementing or reviewing Go code, adding features, refactoring, or when the user asks to follow project rules or standards. Ensures compliance with ai_go/v1/rules (project_architecture.md, code_style.md) and .cursor/rules.
development
Use when implementing JWT token signing or verification in Go projects. Covers ES256 (ECDSA, recommended), PS256/RS256 (RSA asymmetric), and HS256 (HMAC symmetric) signing methods, with keys loaded from file path or inline string. Places the jwt package under pkg/jwt for new projects.
tools
Use when writing or reviewing Go imports, especially when a repository has existing formatting automation or import-grouping conventions that must be preserved.
development
Recommends and scaffolds frontend technology stack for new projects. Use when starting a new frontend project, selecting a framework, setting up a web app from scratch, or when the user asks about frontend tech stack, scaffolding, or architecture selection. Covers React/Next.js/Astro/Vue, TypeScript, Tailwind CSS, state management, data fetching, UI components, testing, and monorepo setup.