Skip to content

Commit

Permalink
Converted to go.mod and updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Vachon committed Feb 2, 2019
1 parent 0f88efa commit 8fce577
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 1,125 deletions.
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ 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:
And formats it to (with coloring):

```
[2018-12-10 17:06:24.101 UTC] INFO (main.go:45) doing some stuff {"count":2}
```

**NOTE** Only compatible with `zapdriver.NewProduction` format and the likes for now.
Compatible with `zap.NewProduction` and `zapdriver.NewProduction` formats out of the box.

## Install

```sh
$ go get -u github.com/maoueh/zap-pretty
```

**Note** Source installation requires Go 1.11+.

## Usage

Simply pipe the output of the CLI tool generating Zap JSON log lines to the `zap-pretty` tool:
Expand All @@ -33,25 +35,39 @@ zap_instrumented | zap-pretty

#### No Conversion

- Ensures that JSON line you are seeing is redirected to standard output, check if it works
when doing `zap_instrumented &> /dev/null | zap-pretty`.
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`.

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

This package is a "work in progress". Current version works but it's the initial version, still
much more to do to make it production ready:
```
return zap.NewProduction()
```

- Support the various encoding config supported by Zap
- Add CLI arguments similar to [pino-pretty](https://github.com/pinojs/pino-pretty#cli-arguments)
- Add suppressing field for JSON output (with CLI argument to add more)
- Refactor code to be more "nice"
- Filtering support of log statements?
- Other ideas?
To:

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

### CLI Arguments

None for now.

## License

MIT License
MIT License
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module github.com/maoueh/zap-pretty

require (
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e
github.com/stretchr/testify v1.3.0
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e h1:9MlwzLdW7QSDrhDjFlsEYmxpFyIoXmYRon3dt0io31k=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
23 changes: 0 additions & 23 deletions vendor/github.com/logrusorgru/aurora/CHANGELOG.md

This file was deleted.

13 changes: 0 additions & 13 deletions vendor/github.com/logrusorgru/aurora/LICENSE

This file was deleted.

223 changes: 0 additions & 223 deletions vendor/github.com/logrusorgru/aurora/README.md

This file was deleted.

Loading

0 comments on commit 8fce577

Please sign in to comment.