Giter Club home page Giter Club logo

zap-pretty's Introduction

zap-pretty

This module provides a basic log prettifier for the zap logging library. It reads a standard Zap JSON log line:

{"severity":"INFO","time":"2018-12-10T17:06:24.10107832Z","caller":"main.go:45","message":"doing some stuff","count":2}

And formats it to:

The tool receives JSON lines, determines if they seems like a log line of a supported format and pretty print it to standard output.

Support Zap logging formats:

  • zap.NewProduction
  • zapdriver.NewProduction

Install

Homebrew

brew install maoueh/tap/zap-pretty

Binary

Download the binary package for your platform, the list is available at https://github.com/maoueh/zap-pretty/releases.

Unpack the binary somewhere on your disk and ensure the binary is in a directory included in your $PATH variable.

Source

go install github.com/maoueh/zap-pretty@latest

Note Source installation requires Go 1.16+.

Usage

Simply pipe the output of the CLI tool generating Zap JSON log lines to the zap-pretty tool:

zap_instrumented | zap-pretty

The tool supports Zap standard production format as well as the Zapdriver standard format (for consumption by Google Stackdriver).

Zapdriver

When using the Zapdriver format, those fields are removed by default from the prettified version to reduce the clutter of the logs:

  • labels
  • serviceContext
  • logging.googleapis.com/labels
  • logging.googleapis.com/sourceLocation

If you want to see those fields, you can use --all flag:

zap_instrumented | zap-pretty --all

CLI Arguments

  • --all - Show all fields of the line, even those filtered out by default for the active logger format (default false).
  • --version - Show version information.
  • -n - Format JSON as multiline if got more than n elements in data (default 3).

Troubleshoot

No Conversion

By default, when using zap.NewProductionConfig(), all log statements are issued on the /dev/stderr stream. That means that if you plainly do zap_instrumented | zap-pretty, your JSON lines will not be prettified.

Why? Simply because you are actually piping only the stdout stream to zap-pretty but your actual log statements are written on stderr so they never make their way up to zap-pretty.

Ensures that JSON line you are seeing is redirected to standard output, if it works when doing zap_instrumented 2>&1 | zap-pretty, then it means logs are going out to stderr.

You can live like this, but if you want to customize your logs to output to stdout instead, simply perform the following changes:

    return zap.NewProduction()

To:

    config := zap.NewProductionConfig()
    config.OutputPaths = []string{"stdout"}
    config.ErrorOutputPaths = []string{"stdout"}

    return config.Build()

License

MIT License

zap-pretty's People

Contributors

maoueh avatar vany-egorov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

zap-pretty's Issues

Filtering support of log statements

It would probably be nice to be able to filter out some log statements.

I think about error level first, would be a good start. We could maybe support a search pattern in a second time.

go get -u fails, possibly outdated method signature for auoroa

Running go get -u https://github.com/maoueh/zap-pretty results in an error:

go: finding github.com/maoueh/zap-pretty v0.2.0
go: downloading github.com/maoueh/zap-pretty v0.2.0
go: extracting github.com/maoueh/zap-pretty v0.2.0
go: downloading github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e
go: extracting github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e
go: finding github.com/logrusorgru/aurora latest
go: downloading github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381
go: extracting github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381
# github.com/maoueh/zap-pretty
../../../go/pkg/mod/github.com/maoueh/[email protected]/main.go:190:25: not enough arguments in call to aurora.Gray
	have (string)
	want (uint8, interface {})

Pretty print stacktrace

The stacktrace could be pretty formatted and removed from the JSON output when present. The stack trace could be show below the actual JSON output, maybe a little offset from the rest.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.