maratori / errors

Go library to construct errors with fields for structured logging

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

errors
go.mod version CI Codecov Maintainability Go Report Card License Go Reference

Go library to construct errors with fields for structured logging.

Features:

  • Wrap an error with string prefix
  • Add custom fields to an error
  • Extract all fields from chain of wrapped errors
  • Join several errors into one error (build errors tree)
  • Extract paths to each leaf from the errors tree
  • Logger agnostic

Motivation

When structured logger is used, it's better to have constant error messages. For example, message should not contain ID of your entity. Instead, such additional data should be logged in a separate fields. That makes it easier to search, group and analyse logs.

Bad:

{"level": "error", "message": "can't find order a881ff5c-ef23-4e6c-a505-9b66ee42b779"}

Good:

{"level": "error", "message": "can't find order", "order_id": "a881ff5c-ef23-4e6c-a505-9b66ee42b779"}

Installation

go get github.com/maratori/errors

Usage

TBD

Contribution

You are welcome to create an issue or pull request with improvements and fixes. See guide.

License

MIT License

About

Go library to construct errors with fields for structured logging

License:MIT License


Languages

Language:Go 91.3%Language:Makefile 7.5%Language:Dockerfile 1.2%