본문으로 건너뛰기
cccskills
무료GitHub에 공개

zerolog-observability

Use when adding logging to Go code - the repository's logger with structured fields, request-scoped correlation, correct levels, no secrets or double-logging

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md4.5 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Structured Logging (Go)

Overview

Logs are for machines first: structured fields you can filter and correlate, not prose. The recurring defects are fmt.Println debugging left in, data interpolated into the message instead of fields, the same error logged at every layer, and secrets leaking into logs.

Core principle: log the failure at its site, with fields, once — and use the repository's own logger.

Which logger

Follow the repository's existing logger: github.com/rs/zerolog, log/slog (stdlib), or go.uber.org/zap all give structured fields and are fine to continue. Use zerolog only when the repo has no logger yet. Never introduce a second logging library alongside one the repo already uses (rule repo-conventions-win). Never fmt.Println / log.Printf in production code regardless of which structured logger the repo picked.

Rules

  • Fields, not interpolation: ids and operation names are structured fields, not baked into the message string.

  • Correlate with a request-scoped logger, not the global one. Middleware attaches request_id (and relevant entity ids) once and puts the enriched logger in the request's context; handlers and services pull it back out instead of re-adding the id everywhere:

    // middleware, once per request
    l := log.With().Str("request_id", reqID).Logger()
    c.SetUserContext(l.WithContext(c.UserContext()))
    
    // anywhere downstream
    zerolog.Ctx(ctx).Error().Err(err).Str("task_id", id.String()).Msg("dispatch failed")
    

    (slog: slog.Default().With("request_id", reqID) carried the same way via context, or a custom Handler.)

  • Handle errors once (samber "single handling rule" / Uber "Handle Errors Once"): an error is either logged OR returned/wrapped, never both. Log-and-return at every layer reports the same failure N times. Log at the site that has the most context (usually where it's finally handled, e.g. the HTTP error mapper), propagate elsewhere with %w and say nothing.

  • Never log secrets, tokens, full request bodies, or other PII that may carry user data. Treat user-supplied strings as values only — never splice them into the message template (log injection: a user-controlled newline or field name can forge log entries).

Levels

LevelUse for
Debugdevelopment detail, verbose tracing
Infostate changes worth auditing (task moved, migration applied)
Warnhandled anomaly (retry, fallback taken)
Errora failure needing attention

Worked Example

// ❌ prose message, interpolated id, will be logged again by the caller too
log.Error().Msg(fmt.Sprintf("dispatch failed for task %s: %v", id, err))

// ✅ structured fields, error attached, logged once at the handling site, request-scoped logger
zerolog.Ctx(ctx).Error().
    Err(err).
    Str("task_id", id.String()).
    Str("op", "dispatch").
    Msg("dispatch failed")
// upstream callers propagate with fmt.Errorf("dispatch: %w", err) — they do NOT re-log

Now a query like op="dispatch" level="error" finds every dispatch failure with its task id and request id, and each failure appears exactly once.

Java

Follow the repo's existing setup: SLF4J (with JBoss Logging or Logback underneath) using MDC for request_id and other correlation fields; Spring Boot's built-in structured logging (logging.structured.format.console=ecs, 3.4+); or Quarkus's quarkus-logging-json extension. The same rules apply — fields not string concatenation, handle once, never log secrets.

Common Mistakes

  • fmt.Println/log.Printf left in production paths.
  • Msg(fmt.Sprintf(...)) interpolating ids instead of .Str(...) fields.
  • The same error logged in the repo, the service, AND the handler.
  • Logging a token, password, or full request body.
  • Reading request_id from a global/package variable instead of the request-scoped context logger.
  • Everything at Info (or everything at Error) — levels lose meaning.

Red Flags

  • A message string with %s/+id inside it.
  • The same failure appears three times in the logs for one request.
  • A secret or auth header value in a log line.
  • User input spliced directly into a log message template rather than passed as a field value.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Use when writing acceptance criteria for a task - express each as an observable Given/When/Then that QA can execute, including negative cases

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 20일 업데이트

Use when the diff adds or changes an endpoint, resolver, RPC, job or query that takes an object id, a role check, a request binding or a tenant filter - BOLA/IDOR, function-level authorization, mass assignment and tenant scoping

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 20일 업데이트

Use on every UI change - semantic HTML, labels for controls, keyboard-navigable dialogs/menus, visible focus, and never color as the only signal

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 20일 업데이트

Use when a task changes any screen, form, dialog, menu or control - Lighthouse/axe scan of the changed screens, a keyboard walk, and the thresholds that fail a task

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 20일 업데이트

How to work a task returned with review, QA or UAT findings. Use when a task is in need_revision or PR review comments are in your context.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 20일 업데이트

Use when the repository keeps its alerting in code, or a person asks for alerts outside TaskTrooper - PrometheusRule YAML, a Cloud Monitoring alert policy in Terraform, a Datadog monitor, each routed to TaskTrooper's alert ingest URL so it opens an incident here

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 20일 업데이트

makifbaysal의 스킬 모두 보기

이 스킬의 문제 신고