Skip to content

Latest commit

 

History

History
86 lines (53 loc) · 2.62 KB

README.md

File metadata and controls

86 lines (53 loc) · 2.62 KB

Erro: Faster and easier Go debugging in case of an error

Build state Go Version Version Issues Report

gopherbadger-tag-do-not-edit

Initially forked from snwfdhmp/errlog

Erro (pronounced 'arrow') is a simple tool that helps finding the reasons for errors in your code.

Currently supported languages:

  • Golang

Piping your structured log into erro

yourProgram 2>&1 | erro

turns

Erro example structured log

into

Erro example pipe output

In an IDE like JetBrains Golang, the line where the error comes from is clickable and takes you to that line.

Erro example Jetbrains output

Example code

func main() {
    logger := log.With().Caller().Logger()

    logger.Info().Msg("Welcome to erro 🧑‍🚀")
    logger.Info().Msg("https://github.com/inkmi/erro")
    logger.Info().Int("Hello", 42).Msg("Info example")
    logger.Trace().Int("Hello", 23).Msg("Trace example")
    logger.Debug().Str("Hello", "🦄").Msg("Debug example")
    logger.Warn().Str("Hello", "World").Msg("Warn example")

    err := errors.New("Testerror")
    logger.Error().Err(err).Str("Test", "Test").Msg("Error example")
    logger.Info().Int("After", 1).Int("Days", 2).Msg("After the error")
}

Install

go install github.com/inkmi/erro

The log data needs to be structured as JSON.

The log data needs to include caller information, for example

{ "caller": "testerro.go:22" }

Configuration depends on your logging library, for Zerolog it's

logger := log.With().Caller().Logger()

After make build you can test erro with

./bin/testerro 2>&1| ./bin/erro

License information

MIT License

Contributors

Major

  • Stephan Schmidt: Author and maintainer
  • Martin Joly wrote the original errlog which this code is based on