import (
"context"
"log/slog"
"github.com/n-r-w/ctxlog"
)
func main() {
// Parse level from environment variable
// (here we hardcode it for demonstration)
level, err := ctxlog.ParseLogLevel("DEBUG")
if err != nil {
panic(err)
}
// create context with logger
ctx := ctxlog.MustContext(
context.Background(),
ctxlog.WithName("myapp"),
ctxlog.WithLevel(level),
)
// simple format (key/value pairs)
ctxlog.Info(ctx, "starting application", "version", "1.0.0")
// slog attr fields
ctxlog.Debug(ctx, "connecting to database",
slog.String("host", "localhost"),
slog.Int("port", 5432),
)
// enrich context with more fields
ctx = ctxlog.WithGroup(ctx, "database")
ctx = ctxlog.With(ctx, "user_id", "12345", "ip", "192.168.1.1")
ctxlog.Error(ctx, "some error occurred")
// extract logger from context for direct usage
logger := ctxlog.FromContext(ctx)
logger.Warn(ctx, "direct usage of logger")
}
```
</example>
github.com/n-r-w/ctxlog guidelines
Guidelines and examples for using the ctxlog logging package.
github.com/n-r-w/ctxlog guidelines by diegosouzapw · 63d7c60
npx skillmds@latest add diegosouzapw/github-com-n-r-w-ctxlog-guidelines File contents
---name: github-com-n-r-w-ctxlog-guidelinesdescription: Guidelines and examples for using the ctxlog logging package.---<ctxlog name="github.com/n-r-w/ctxlog guidelines"> <instructions> - Import path: `github.com/n-r-w/ctxlog`. - Primary workflow: - Parse log level from environment variable or config: `ctxlog.ParseLogLevel()` - Create a logger once (app startup, request entrypoint, job runner) and store it in a context - Log everywhere via context-based helpers: `ctxlog.Debug/Info/Warn/Error(ctx, msg, ...)` - Enrich the context logger when you need extra fields: `ctx = ctxlog.With(ctx, ...)` - Group related fields: `ctx = ctxlog.WithGroup(ctx, "group")` - Passing structured fields: - You can pass key/value pairs: `"user_id", "12345"` - You can pass `slog.Attr` values: `slog.String("host", "localhost")` - When passing key/value pairs, the number of arguments must be even (key-value-key-value...) - Optional: extract the logger from context for direct usage: `logger := ctxlog.FromContext(ctx)` - For external dependencies that should not depend on the concrete logger type, use `ctxlog.ILogger` via `ctxlog.NewWrapper()` (real) or `ctxlog.NewStubWrapper()` (no-op) </instructions> <example> ```go package main import ( "context" "log/slog" "github.com/n-r-w/ctxlog" ) func main() { // Parse level from environment variable // (here we hardcode it for demonstration) level, err := ctxlog.ParseLogLevel("DEBUG") if err != nil { panic(err) } // create context with logger ctx := ctxlog.MustContext( context.Background(), ctxlog.WithName("myapp"), ctxlog.WithLevel(level), ) // simple format (key/value pairs) ctxlog.Info(ctx, "starting application", "version", "1.0.0") // slog attr fields ctxlog.Debug(ctx, "connecting to database", slog.String("host", "localhost"), slog.Int("port", 5432), ) // enrich context with more fields ctx = ctxlog.WithGroup(ctx, "database") ctx = ctxlog.With(ctx, "user_id", "12345", "ip", "192.168.1.1") ctxlog.Error(ctx, "some error occurred") // extract logger from context for direct usage logger := ctxlog.FromContext(ctx) logger.Warn(ctx, "direct usage of logger") } ``` </example></ctxlog>
diegosouzapw/awesome-omni-skill/tree/main/skills/tools/github.com-n-r-w-ctxlog-guidelines commit 63d7c60a1b
Frequently asked questions
Run npx skillmds@latest add diegosouzapw/github-com-n-r-w-ctxlog-guidelines in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Guidelines and examples for using the ctxlog logging package. It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. Capability flags: docs only. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
diegosouzapw (@diegosouzapw) published this skill. Their other Agent Skills are listed on their SkillMD profile.