Skip to main content
Copper provides the clogger package for structured, leveled logging. You may inject clogger.Logger anywhere you need it, and every scaffolded router and service already has one.

Writing Logs

There are four levels. Debug and Info take just a message, while Warn and Error also take an error, which may be nil:
Structured context comes from WithTags:
When you pass an error, tags from its entire cerrors chain are merged into the log automatically, so if you wrap errors well, your logs arrive pre-annotated:

Configuration

The logger is configured under the [clogger] section:
In JSON format, each log is a single object with ts, level, msg, error, and tags, ready for a log aggregator.
level_filter is an allow-list, not a threshold. level_filter = ["error"] logs only errors. If you would like warnings as well, list both.

Redacting Sensitive Fields

In JSON format, redact_fields replaces matching tag values with "redacted" anywhere in the tag tree, including nested objects. Field names match loosely, so redact_fields = ["email"] also catches user_email and emailAddress:
Redaction only works with format = "json". In plain format, setting redact_fields replaces every log message with a placeholder rather than risk leaking a field.

Hooks

If you would like to ship logs to an external service, such as an error tracker or a cloud logging platform, implement clogger.Hook:
Hooks run for every log that passes the level filter. You may provide them as a []clogger.Hook in your app’s wire module:
pkg/app/logger.go