Skip to content

feat: switch template logging to native slog.LogAttrs#34

Merged
ankurs merged 8 commits intomainfrom
feat/slog-default-logging
Apr 12, 2026
Merged

feat: switch template logging to native slog.LogAttrs#34
ankurs merged 8 commits intomainfrom
feat/slog-default-logging

Conversation

@ankurs
Copy link
Copy Markdown
Member

@ankurs ankurs commented Apr 11, 2026

Summary

  • Switch all 5 logging call sites from go-coldbrew/log to native slog.LogAttrs with typed attrs
  • Demonstrates the zero-boxing high-performance logging path
  • service/service.go Echo handler shows AddAttrsToContext + slog.LogAttrs pattern
  • Only go-coldbrew/log import remaining is for AddAttrsToContext in service.go

Changes

File Before After
service/service.go log.Info(ctx, ...) slog.LogAttrs(ctx, slog.LevelInfo, ...) + AddAttrsToContext demo
service/auth/auth.go log.Warn(ctx, ...) slog.LogAttrs(ctx, slog.LevelWarn, ..., slog.String(...))
main.go log.Error(ctx, cb.Run()) slog.LogAttrs(ctx, slog.LevelError, ..., slog.Any("err", err))
config/config.go log.Error(ctx, ...) slog.LogAttrs(ctx, slog.LevelError, ..., slog.Any("err", err))

Test plan

  • Generate a project from the template and run make test && make lint

Ref: go-coldbrew/log#27

Summary by CodeRabbit

  • Documentation

    • Expanded context propagation guidance with recommendations for structured logging and adding typed context fields.
  • Chores

    • Standardized logging on Go's structured logger and improved error reporting during startup and configuration load.
    • Bumped ColdBrew-related dependency versions.
    • Adjusted project generation/tidy steps for a more resilient init flow.

Replace all go-coldbrew/log calls with native slog.LogAttrs using typed
attribute constructors. Demonstrates the zero-boxing high-performance
logging path enabled by the slog-native Handler (go-coldbrew/log#27).

- service/service.go: slog.LogAttrs + AddAttrsToContext example in Echo handler
- service/auth/auth.go: slog.LogAttrs with slog.String/slog.Any
- main.go: slog.LogAttrs for service exit error
- config/config.go: slog.LogAttrs for config load error

No go-coldbrew/log import needed except in service.go for AddAttrsToContext.

Ref: go-coldbrew/log#27
Copilot AI review requested due to automatic review settings April 11, 2026 14:33
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 11, 2026

📝 Walkthrough

Walkthrough

Replaced ColdBrew logging wrapper usage with Go's log/slog across the app, updated ColdBrew dependency versions, adjusted config/main error logging, added context-field logging guidance to docs, and changed Echo to accept and use a context.Context parameter.

Changes

Cohort / File(s) Summary
Documentation
AGENTS.md
Added context propagation and logging guidance: prefer slog.LogAttrs(ctx, ...); note ColdBrew's Handler injects context fields and use github.com/go-coldbrew/log.AddAttrsToContext (aliased cblog).
Config & Startup
config/config.go, main.go
Replaced ColdBrew log calls with slog.LogAttrs(...) for config load errors and service exit; uses context.Background() for config error logging.
Auth Logging
service/auth/auth.go
Switched warning logs from ColdBrew helper to slog.LogAttrs(ctx, slog.LevelWarn, ...), keeping method and err attributes (using slog.String/slog.Any).
Service Core
service/service.go
Changed Echo signature to accept ctx context.Context; add typed context attrs via cblog.AddAttrsToContext(...) and emit info logs with slog.LogAttrs(...); adjusted imports to include cblog and log/slog.
Dependencies
go.mod
Bumped ColdBrew-related dependency versions: core, errors, interceptors, log (direct) and tracing (indirect).
Project Hooks
hooks/post_gen_project.py
Inserted a pre-mock go mod tidy -e step, updated step numbering/text, and made pre-mock tidy non-fatal; make mock and final go mod tidy shifted to subsequent steps.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • fajran
  • kevinjom
  • wdevarshi

Poem

🐇 I nudged my logs from wrappers to slog's warm light,
Context carrots added, shining tidy and bright,
Echo listens now with a mindful hop,
Attributes tucked in — no more log-stop,
Hooray for clean hops and structured delight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: switching the template's logging approach from go-coldbrew/log to native slog.LogAttrs across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/slog-default-logging

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the template’s logging approach by replacing go-coldbrew/log call sites with native log/slog LogAttrs usage, while keeping go-coldbrew/log only for context attribute propagation.

Changes:

  • Replace log.Info/Warn/Error calls with slog.LogAttrs and typed attrs (slog.String, slog.Any).
  • Add an Echo example demonstrating AddAttrsToContext + slog.LogAttrs.
  • Update service exit/config error logging to use slog with err attribute.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
{{cookiecutter.app_name}}/service/service.go Switch handler logging to slog.LogAttrs and demonstrate request-scoped attrs via AddAttrsToContext.
{{cookiecutter.app_name}}/service/auth/auth.go Convert auth failure warnings to slog.LogAttrs with typed attributes.
{{cookiecutter.app_name}}/main.go Log cb.Run() failures using slog.LogAttrs and err attr.
{{cookiecutter.app_name}}/config/config.go Log config-load failures using slog.LogAttrs with err attr.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread {{cookiecutter.app_name}}/service/service.go Outdated
Comment thread {{cookiecutter.app_name}}/main.go
Comment thread {{cookiecutter.app_name}}/service/service.go Outdated
- Log message length instead of raw user input in Echo handler (Copilot)
- Update AGENTS.md to mention slog.LogAttrs and AddAttrsToContext (Copilot)
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the generated service template to use Go’s native structured logging (log/slog) via the high-performance slog.LogAttrs API while keeping ColdBrew context attribute injection available for request-scoped fields.

Changes:

  • Replaced go-coldbrew/log call sites with slog.LogAttrs and typed attrs (slog.String, slog.Any, etc.).
  • Added an Echo example showing AddAttrsToContext + slog.LogAttrs usage.
  • Updated template guidance in AGENTS.md to reflect the new logging approach.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
{{cookiecutter.app_name}}/service/service.go Uses slog.LogAttrs and demonstrates adding typed attrs to context.
{{cookiecutter.app_name}}/service/auth/auth.go Switches auth warning logs to slog.LogAttrs with typed attrs.
{{cookiecutter.app_name}}/main.go Logs service exit errors via slog.LogAttrs instead of go-coldbrew/log.
{{cookiecutter.app_name}}/config/config.go Logs config-load errors via slog.LogAttrs.
{{cookiecutter.app_name}}/AGENTS.md Updates developer guidance to mention slog.LogAttrs and context attrs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread {{cookiecutter.app_name}}/service/service.go Outdated
Comment thread {{cookiecutter.app_name}}/AGENTS.md Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
{{cookiecutter.app_name}}/AGENTS.md (1)

61-61: Consider clarifying the “context is first parameter everywhere” wording.

This line can be read as absolute; repo convention exempts purely structural unexported helpers that do not propagate/use context. A brief qualifier would prevent over-application.

Based on learnings: In {{cookiecutter.app_name}}/**/*.go, the context-first rule applies to exported functions and unexported functions that actually propagate/use context; purely structural helper functions are exempt.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @{{cookiecutter.app_name}}/AGENTS.md at line 61, Clarify the absolute wording
about context by changing the sentence that currently reads "context.Context is
the first parameter everywhere" to a qualified rule: state that in
{{cookiecutter.app_name}}/**/*.go the convention is to place context.Context
first for exported functions and for unexported functions that propagate or use
context, while purely structural/unrelated private helper functions are exempt;
keep references to interceptors, slog.LogAttrs, ColdBrew Handler, and
github.com/go-coldbrew/log.AddAttrsToContext (cblog) intact so readers still
know how to add typed fields and propagate trace/log options.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @{{cookiecutter.app_name}}/go.mod:
- Line 18: Replace the unavailable module version by updating the dependency
declaration for github.com/go-coldbrew/log to a proxy-indexed release (e.g.,
change v0.4.0 to v0.3.2) in go.mod so the Go module proxy can resolve it; after
editing run `go mod tidy`/`go get` to ensure the lockfile and module cache are
updated and verify the build succeeds.

In @{{cookiecutter.app_name}}/service/service.go:
- Around line 71-74: The Error handler (svc.Error) currently creates a plain
error with errors.New and returns errors.Wrap, which doesn't produce a gRPC
status; change it to return a gRPC status error using
status.Error(codes.Internal, "...") (or status.Errorf) with the same message,
keep the slog.LogAttrs(ctx, slog.LevelInfo, "error requested") call, and remove
the errors.Wrap usage so the function returns (nil, status.Error(codes.Internal,
"<endpoint error message>")) to match other endpoints like healthcheck.go and
auth.go.

---

Nitpick comments:
In @{{cookiecutter.app_name}}/AGENTS.md:
- Line 61: Clarify the absolute wording about context by changing the sentence
that currently reads "context.Context is the first parameter everywhere" to a
qualified rule: state that in {{cookiecutter.app_name}}/**/*.go the convention
is to place context.Context first for exported functions and for unexported
functions that propagate or use context, while purely structural/unrelated
private helper functions are exempt; keep references to interceptors,
slog.LogAttrs, ColdBrew Handler, and
github.com/go-coldbrew/log.AddAttrsToContext (cblog) intact so readers still
know how to add typed fields and propagate trace/log options.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d73db4d-2311-46ef-8d38-0b5dca4737be

📥 Commits

Reviewing files that changed from the base of the PR and between c1e97ba and 1214f15.

📒 Files selected for processing (6)
  • {{cookiecutter.app_name}}/AGENTS.md
  • {{cookiecutter.app_name}}/config/config.go
  • {{cookiecutter.app_name}}/go.mod
  • {{cookiecutter.app_name}}/main.go
  • {{cookiecutter.app_name}}/service/auth/auth.go
  • {{cookiecutter.app_name}}/service/service.go

Comment thread {{cookiecutter.app_name}}/go.mod Outdated
Comment thread {{cookiecutter.app_name}}/service/service.go
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the generated ColdBrew Go service template to use Go’s native log/slog structured logging APIs (slog.LogAttrs) while preserving ColdBrew’s context-based attribute propagation via AddAttrsToContext.

Changes:

  • Replaced prior go-coldbrew/log call sites with slog.LogAttrs using typed slog.Attrs.
  • Added an Echo example demonstrating cblog.AddAttrsToContext + slog.LogAttrs.
  • Updated template docs and bumped github.com/go-coldbrew/log to v0.4.0.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
{{cookiecutter.app_name}}/service/service.go Switches service logs to slog.LogAttrs and demonstrates AddAttrsToContext usage.
{{cookiecutter.app_name}}/service/auth/auth.go Converts auth warning logs to slog.LogAttrs with typed attrs.
{{cookiecutter.app_name}}/main.go Logs cb.Run() failure via slog.LogAttrs instead of the ColdBrew logging helper.
{{cookiecutter.app_name}}/config/config.go Uses slog.LogAttrs for config-load errors.
{{cookiecutter.app_name}}/go.mod Updates github.com/go-coldbrew/log dependency to v0.4.0.
{{cookiecutter.app_name}}/AGENTS.md Documents the slog.LogAttrs + AddAttrsToContext pattern for service code.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- core v0.1.45 → v0.1.51 (slog-native SetupLogger, DefaultIsSet)
- log v0.3.1 → v0.4.1 (slog-native Handler, AddAttrsToContext, DefaultIsSet)
- errors v0.2.13 → v0.2.15
- interceptors v0.1.20 → v0.1.25
- tracing v0.2.1 → v0.2.2
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the template to use Go’s native log/slog structured logging API (via slog.LogAttrs) in runtime code paths, while keeping go-coldbrew/log only for context attribute propagation.

Changes:

  • Replaced ColdBrew log.* calls with slog.LogAttrs across service, auth, config, and main entrypoint.
  • Added an Echo example demonstrating AddAttrsToContext + slog.LogAttrs.
  • Bumped several go-coldbrew/* module versions in go.mod.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
{{cookiecutter.app_name}}/service/service.go Switches to slog.LogAttrs and demonstrates adding typed request attrs via context.
{{cookiecutter.app_name}}/service/auth/auth.go Converts auth failure logging to slog.LogAttrs with typed attrs.
{{cookiecutter.app_name}}/main.go Logs cb.Run() error using slog.LogAttrs (with err attr).
{{cookiecutter.app_name}}/config/config.go Converts config-load error logging to slog.LogAttrs.
{{cookiecutter.app_name}}/go.mod Updates ColdBrew module versions.
{{cookiecutter.app_name}}/AGENTS.md Documents the new slog.LogAttrs + AddAttrsToContext logging guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread {{cookiecutter.app_name}}/AGENTS.md
Comment thread {{cookiecutter.app_name}}/service/service.go
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
hooks/post_gen_project.py (1)

54-56: Use absolute paths or path resolution for subprocess commands to harden bootstrap execution.

Bare command names in Popen([...]) rely on PATH lookup, which is avoidable in bootstrap scripts. This affects all subprocess calls in the file (lines 43, 49, 56, 59, 65). Use absolute paths (e.g., /usr/bin/go) or shutil.which() to resolve them explicitly before execution.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@hooks/post_gen_project.py` around lines 54 - 56, Replace bare command names
in all Popen([...]) calls with resolved absolute paths: use shutil.which to
locate the executable (e.g., resolve "go" via shutil.which("go") and error if
not found) and then pass the resolved path as the first element of the argv list
to Popen; update every subprocess invocation in this file (the Popen calls
around PROJECT_DIRECTORY) to use the resolved executable path and keep the cwd
and flags unchanged so bootstrap execution doesn't rely on PATH lookups.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@hooks/post_gen_project.py`:
- Around line 54-56: The pre-mock "go mod tidy -e" step currently ignores the
process exit status; update the Popen call in hooks/post_gen_project.py (the
Popen invocation that runs ["go","mod","tidy","-e"] with cwd=PROJECT_DIRECTORY)
to capture the completed process, check its returncode, and handle non-zero
results explicitly (log/print the stderr/stdout for context and abort/raise
SystemExit with a non-zero exit code) so real module errors stop the post-gen
script instead of allowing later, harder-to-debug failures.
- Line 48: Update the progress step totals so they are consistent across the
prints: find the print statements showing "Step 1/4" and "Step 2/5" (and any
other "Step X/Y" strings) and change them to reflect the new total of 5 steps
(e.g., "Step 1/5", "Step 2/5", etc.) so all CLI progress messages use the same
denominator; ensure you update every occurrence of the literal "Step X/Y" in the
script (search for the exact strings "Step 1/4" and "Step 2/5") to avoid mixed
totals.

---

Nitpick comments:
In `@hooks/post_gen_project.py`:
- Around line 54-56: Replace bare command names in all Popen([...]) calls with
resolved absolute paths: use shutil.which to locate the executable (e.g.,
resolve "go" via shutil.which("go") and error if not found) and then pass the
resolved path as the first element of the argv list to Popen; update every
subprocess invocation in this file (the Popen calls around PROJECT_DIRECTORY) to
use the resolved executable path and keep the cwd and flags unchanged so
bootstrap execution doesn't rely on PATH lookups.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d75e228d-d56e-44ac-b33f-5ca22338a80b

📥 Commits

Reviewing files that changed from the base of the PR and between d692fd2 and 571e9f6.

📒 Files selected for processing (1)
  • hooks/post_gen_project.py

Comment thread hooks/post_gen_project.py
Comment thread hooks/post_gen_project.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the generated service template to use Go’s native structured logging (log/slog) via slog.LogAttrs, while keeping github.com/go-coldbrew/log only for adding typed context attributes.

Changes:

  • Replaced ColdBrew log.* call sites with slog.LogAttrs(...) (and typed attrs) across service, auth, main, and config.
  • Added an AddAttrsToContext + slog.LogAttrs example in Echo.
  • Updated proto init hook sequencing and bumped several ColdBrew dependency versions.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
hooks/post_gen_project.py Adds a pre-mock go mod tidy -e step and updates progress step counts.
{{cookiecutter.app_name}}/service/service.go Switches to slog.LogAttrs and demonstrates AddAttrsToContext typed attrs.
{{cookiecutter.app_name}}/service/auth/auth.go Replaces warn logging with slog.LogAttrs + typed attrs.
{{cookiecutter.app_name}}/main.go Logs cb.Run() error using slog.LogAttrs when non-nil.
{{cookiecutter.app_name}}/config/config.go Logs config load errors using slog.LogAttrs.
{{cookiecutter.app_name}}/go.mod Updates ColdBrew module versions (core/errors/interceptors/log/tracing).
{{cookiecutter.app_name}}/AGENTS.md Documents slog.LogAttrs + go-coldbrew/log.AddAttrsToContext pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hooks/post_gen_project.py Outdated
Comment thread hooks/post_gen_project.py Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@hooks/post_gen_project.py`:
- Line 44: Replace PATH-dependent executable names with absolute paths resolved
via shutil.which for all Popen invocations in both init_proto() and init_git():
locate every Popen([...], cwd=PROJECT_DIRECTORY) that uses "go", "make" or "git"
(in init_proto() — the calls at lines corresponding to the five go/make
invocations; and in init_git() — the four entries in GIT_COMMANDS) and resolve
each command before calling Popen; if shutil.which returns None for any of the
executables ("go", "make", "git"), log an error and exit/raise instead of
invoking Popen to avoid PATH injection. Ensure you update the command lists
passed to Popen to use the resolved executable paths while keeping the original
arguments unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c0f2a911-00e5-421f-ae52-e63a0a3bdabf

📥 Commits

Reviewing files that changed from the base of the PR and between 571e9f6 and 1d86b56.

📒 Files selected for processing (1)
  • hooks/post_gen_project.py

Comment thread hooks/post_gen_project.py
@ankurs ankurs merged commit 5b9a2b3 into main Apr 12, 2026
8 checks passed
@ankurs ankurs deleted the feat/slog-default-logging branch April 12, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants