Skip to content
Back to skills

Logging Setup

ASecurity

Structured logging: slog/pino, Cloud Logging, Loki, correlation IDs, PII scrubbing, sampling, cost control.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 14, 2026
securitygoreactnodegcpdebuggingapifrontend

Works with

  • api

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned November 14, 2026

npx -y skills add SebastianLuser/claude-code-arcane --skill logging-setup --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Logging Setup?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Logging Setup
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sebastianluser-logging-setup/badge)](https://www.skillsdirectory.com/skills/sebastianluser-logging-setup)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: logging-setup
description: "Structured logging: slog/pino, Cloud Logging, Loki, correlation IDs, PII scrubbing, sampling, cost control."
category: "observability"
argument-hint: "[stack: go|ts|react|rn]"
user-invocable: true
allowed-tools: Read, Glob, Grep, Write, Edit, Task
---
# logging-setup — Structured Logging

Goal: **debuggable in prod, cheap at scale, no PII**.

## Principles

1. Always structured JSON — never free-form strings in prod
2. One line = one event — no multi-line/pretty-print
3. Level + message + context on every event
4. Correlation ID (trace_id, request_id, user_id, tenant_id) on every line
5. No PII — scrubber in the logger
6. Sampling on hot paths
7. Logs ≠ errors ≠ metrics ≠ traces — each has its own destination

## Stack Decision

| Destination | When |
|---------|--------|
| **GCP Cloud Logging** | **Educabot default** (GCP runtime), $0.50/GiB ingest |
| Grafana Loki | Self-host, cheap high volume |
| Datadog Logs | If you already pay for DD APM |
| ELK/OpenSearch | Compliance/SIEM full-text |

Default: Cloud Logging (runtime) + Loki (high volume/cheap retention).

## Setup per Stack

**Go (slog stdlib 1.21+):** `slog.NewJSONHandler` with a configurable level, ReplaceAttr for PII scrubbing, base fields (service, env, version). Gin middleware injects request-scoped attrs (request_id, trace_id, route) into the context.

**Node/TS (pino):** level via env, base fields, `redact.paths` for PII (password, token, authorization, cookie, dni, cuit), `pinoHttp` middleware with custom props (trace_id) and compact serializers. Pino > winston: 5x faster, native JSON.

**Cloud Logging fields:** `severity` (DEBUG-CRITICAL), `logging.googleapis.com/trace` (auto-link to Cloud Trace), `httpRequest` (method/status/latency as columns). Cloud Run/GKE: stdout is logged automatically.

**React/frontend:** errors → Sentry, analytics → Mixpanel/Amplitude. If you need centralized logs: buffer + batch + flush to `/api/logs`, only warn+ in prod. Avoid logging routine interactions.

**React Native:** errors → Sentry, analytics → Mixpanel. Field debugging: `react-native-logs` (rotated files), upload with consent. Never PII in device logs.

## Correlation / Trace IDs

OTel W3C Trace Context (`traceparent`). Every log within a request carries the same trace_id. Go: `trace.SpanFromContext(ctx).SpanContext().TraceID()`.

## Log Levels

| Level | Use |
|-------|-----|
| DEBUG | Internal flow. Off in prod except for troubleshooting |
| INFO | Normal events. Prod default |
| WARN | Recoverable ("retry 2/3"). Watch the trends |
| ERROR | An operation fails, the system keeps going. → Sentry too |
| FATAL | The service dies. Rare. Page on-call |

If nobody is going to act on the line → lower its level or remove it.

## Sampling

Cloud Logging ~$0.50/GiB. Strategy: always 100% of errors, sample successes (5-10%). With OTel tracing, lower INFO to 1-5%.

> → Read references/pii-audit-access.md for PII scrubbing fields, audit log schema, access log fields, and retention/cost tables

> → Read references/anti-patterns.md for common logging anti-patterns

> → Read references/checklist.md for the 12-item implementation checklist

## Checklist

- [ ] Log destination chosen and configured (Cloud Logging, Loki, Datadog, or ELK)
- [ ] Correlation IDs (trace_id, request_id) injected in every log line via middleware
- [ ] PII scrubbing in place (password, token, authorization, cookie, dni, cuit redacted)
- [ ] Sampling strategy defined (errors 100%, success paths 5-10%)
- [ ] Log levels set correctly per environment (DEBUG off in prod, INFO as default)
- [ ] JSON structured format enforced — no free-form strings in production

Files in this skill

  • SKILL.md3.6 KB
  • references/anti-patterns.md410 B
  • references/checklist.md508 B
  • references/pii-audit-access.md1.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in security →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.