This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
go-logger is a lightweight Go library that wraps zerolog with automatic log rotation via lumberjack. It's designed as a reusable package, not a standalone application.
logger.go: Main library implementationLoggerstruct: Wrapszerolog.Loggerto provide enhanced functionalityConfigstruct: Configuration for log level, directory, filename, rotation settings, and console outputNew(): Factory function that creates a logger with multi-writer support (file + optional console)- Context methods:
WithField(),WithFields(),WithError()- all return new logger instances preserving immutability
- Wrapper Pattern: The
Loggerstruct embedszerolog.Logger, inheriting all its methods while adding custom functionality - Immutability: Context methods (
WithField,WithFields,WithError) create new logger instances rather than modifying the original - Multi-Writer: Logs can be written to both file and console simultaneously using
io.MultiWriter - Graceful Fallback: If log directory creation fails, the logger falls back to
stderrinstead of failing
- Log files are written to
{LogDir}/{Filename}(default:./logs/go.log) - Automatic rotation when file reaches
MaxSizeMB(default: 10MB) - Keeps
MaxBackupsold files (default: 5) - Automatically deletes logs older than 30 days (hardcoded in
logger.go:86) - Old logs are NOT compressed (
Compress: falseinlogger.go:87)
This project includes specialized Claude Code agents and commands for Go development. Some are shared via a git submodule from claude-code-support-tools.
Shared tools are located in .claude/shared/ as a git submodule. When cloning:
# Clone with submodules
git clone --recurse-submodules <repo-url>
# Or initialize after clone
git submodule update --init --recursiveTo update the submodule to latest:
git submodule update --remote .claude/shared
git add .claude/shared
git commit -m "Update claude-code-support-tools submodule"Invoke agents with @agent-name in your message:
- @go-test-runner - Run tests, analyze coverage, debug failures, write new tests
- @go-code-quality - Run linters/formatters, fix code quality issues, enforce best practices
- @go-dependency-manager - Update dependencies, check for vulnerabilities, manage versions
- @security-auditor - Comprehensive security audits, vulnerability assessments, CVE analysis (shared)
- @project-architect - Analyze project and generate tailored Claude Code agents/commands (shared)
- @code-quality-auditor - Scan for code quality issues and fix warnings
Quick commands for common workflows:
- /test - Run all tests with verbose output
- /test-coverage - Generate coverage report and HTML visualization
- /test-race - Run tests with race detector
- /lint - Check code quality with gofmt, go vet, and golangci-lint
- /fmt - Format all Go files with gofmt
- /mod-tidy - Clean up go.mod and verify dependencies
- /deps-update - Check for and update dependencies
- /benchmark - Run performance benchmarks
- /security-audit - Comprehensive security audit with govulncheck and CVE analysis
- /commit-prepare - Review changes and prepare a commit message
- /commit-do - Create a git commit with the prepared message (shared)
- /setup-project-tools - Generate tailored Claude Code agents/commands for this project (shared)
# Run all tests
go test -v
# Run tests with coverage
go test -cover
# Generate coverage report
go test -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
# Run with race detection
go test -race -v
# Run a specific test
go test -v -run TestNew
# Run tests matching a pattern
go test -v -run TestWith# Build the module (verify compilation)
go build
# Download/update dependencies
go mod download
# Tidy dependencies
go mod tidy
# Verify dependencies
go mod verify# Format code
go fmt ./...
# Run static analysis
go vet ./...
# Run golangci-lint (if installed)
golangci-lint run# Run comprehensive security audit
# Uses govulncheck and generates reports in .audit/ directory
govulncheck ./...
# Check dependencies for vulnerabilities
go list -m all | grep -v "go-logger"Security Audit Reports: Generated by the /security-audit command or @security-auditor agent. All reports are saved to .audit/ directory (gitignored) and include:
- Application code security analysis
- Dependency CVE scanning
- Configuration security review
- Executive summary with prioritized remediation
This project uses GitHub Actions for automated checks:
- CodeQL: Runs on push/PR to master, plus weekly schedule
- Dependency Review: Runs on PRs to detect vulnerable dependencies
Tests use t.TempDir() to create isolated temporary directories for each test case, ensuring no test pollution. The test suite covers:
- Configuration defaults and validation
- Log level parsing (case-insensitive, handles "warn"/"warning")
- File and directory creation (including nested directories)
- Multi-writer scenarios (file + console)
- Context preservation (WithField/WithFields/WithError return new instances)
- Fallback behavior when directory creation fails
When creating a logger, these defaults apply:
Level:"info"if empty or unrecognizedLogDir:"./logs"if emptyFilename:"go.log"if emptyMaxSizeMB:10if zeroMaxBackups:5if zeroConsole:falseby defaultDirMode:0750if zeroDisableCaller:falseby default (caller info included)MaxAge: 30 days (hardcoded, not configurable)
- Per-Instance Level:
New()sets the log level per logger instance via.Level()— no global state pollution - Caller Information: Optional, controlled by
DisableCallerconfig field (logger.go:114). Enabled by default for debugging; disable for privacy/security - Timestamp Format: File logs use Unix timestamp; console uses
"2006-01-02 15:04:05"format - No Compression: Log rotation doesn't compress old files (set
Compress: false) - Close(): Closes the underlying file writer to flush buffered logs (
logger.go:154-159). Always callClose()when done
- Go 1.25.6
github.com/rs/zerologv1.35.0 - Zero-allocation JSON loggergopkg.in/natefinch/lumberjack.v2v2.2.1 - Log file rotation
MIT License - Copyright (c) 2025 Oleg Ivanchenko