tint
A zero-dependency slog.Handler for Go that writes tinted, colorized console logs.
Repository Health
Technical Analysis
tint implements a zero-dependency slog.Handler for Go’s standard-library log/slog package that writes tinted (colorized) logs to the console. Its output format is inspired by zerolog’s ConsoleWriter and slog’s own TextHandler, giving developers readable, color-coded local logs without pulling in a full third-party logging framework.
The handler exposes an Options struct that is a drop-in replacement for slog.HandlerOptions, supporting a configurable minimum level, custom time format, source-location output, and a ReplaceAttr hook for rewriting or dropping attributes before they’re logged. Individual attributes and errors can be tinted with specific ANSI colors via the tint.Attr and tint.Err helpers, and NoColor can disable coloring entirely for non-TTY output such as CI logs or piped files.
What You Get
- A slog.Handler implementation (NewTextHandler) that writes tinted, colorized log lines to any io.Writer
- An Options struct that mirrors slog.HandlerOptions, adding TimeFormat and NoColor fields for console-specific customization
- tint.Attr and tint.Err helpers for coloring individual attributes and errors with a specific ANSI color
- Full support for slog’s ReplaceAttr hook, WithAttrs, and WithGroup, so tint composes with existing slog-based code
- Zero third-party dependencies — only the Go standard library is imported
Common Use Cases
- Coloring local development logs to make level, time, and error attributes easier to scan at a glance
- Replacing zerolog’s ConsoleWriter or a custom text formatter with a stdlib-native slog.Handler
- Auto-detecting terminal capability with go-isatty to enable colors interactively but disable them when output is piped or redirected
- Adding Windows ANSI color support to slog output via the go-colorable writer wrapper
- Customizing or dropping specific attributes (like the time key) globally via ReplaceAttr before they reach the log line
Under The Hood
Architecture tint’s handler struct implements the four methods slog.Handler requires (Enabled, Handle, WithAttrs, WithGroup) in handler.go, holding attrsPrefix/groupPrefix/groups state plus a shared *sync.Mutex and io.Writer so that WithAttrs/WithGroup can clone() a lightweight derived handler without re-locking or duplicating the underlying writer. Handle() pulls a reusable byte buffer from a sync.Pool (buffer.go), appends time, level, optional source, message, and attributes in sequence — injecting ANSI escape sequences inline as it goes — then writes the finished line to the writer under the shared mutex, which is what keeps concurrent writes from clones interleaved correctly.
Tech Stack
The module (go.mod, go 1.21+) depends on nothing but the Go standard library: log/slog for the handler contract, plus context, encoding, fmt, io, path/filepath, reflect, runtime, strconv, strings, sync, time, unicode, and unicode/utf8 for formatting and value inspection. There is no build step beyond go build; CI (.github/workflows/go.yml) runs gofmt, go vet, staticcheck, and go test -race with a faketime build tag for deterministic time-dependent assertions.
Code Quality The single handler_test.go file is extensive relative to the implementation’s size, with table-driven tests (TestHandler, TestHandler_Consistency, TestReplaceAttr, TestAttr), a dedicated concurrency test for mutex sharing across cloned handlers, runnable Example functions doubling as documentation, and benchmarks. Errors are surfaced rather than swallowed, and value-formatting panics (e.g. from a misbehaving TextMarshaler) are recovered and rendered explicitly rather than crashing the caller. CI enforces formatting, vetting, static analysis, and race-detected tests on every push and pull request.
What Makes It Unique tint’s niche is staying entirely inside the standard library’s logging story — rather than replacing log/slog with a separate framework like zerolog or zap, it’s just a Handler implementation, so any code already using log/slog gains colorized console output and per-attribute custom coloring (tint.Attr, tint.Err) by swapping one constructor call, with no additional dependencies or API to learn.
Used by 7 apps in this directory
Authgear
Authentication
Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.
Kuku
Note Taking
A local-first, open-source Markdown knowledge workspace for macOS — plain files, personal wiki and Second Brain workflows, AI-assisted diffs, and encrypted sync, built as an Obsidian alternative.
Multica
AI Assistants · AI Development
Turn coding agents into real teammates — assign issues, track progress, and compound reusable skills across a vendor-neutral, self-hosted platform.
Netdata
Monitoring · Devops
Real-time per-second metrics, ML-powered anomaly detection, and zero-config observability for any infrastructure.
OpenMeter
Invoicing Finance · Developer Tools
Open-source metering and billing engine for AI, agentic, and DevTool monetization — ingest usage events in real time and turn them into accurate invoices automatically.
Teleport
Security · Authentication
Zero-trust infrastructure access platform that replaces credentials and VPNs with short-lived certificates, SSO, and identity-aware proxies for SSH, Kubernetes, databases, RDP, and AI agents.
Uncloud
Devops
Deploy and scale containerised apps across any servers without Kubernetes or Swarm overhead