Created
May 13, 2019 12:42
-
-
Save Clivern/a0154a25a465eabb8ad58eec54f0c927 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "go.uber.org/zap" | |
| "encoding/json" | |
| ) | |
| func main() { | |
| cfg := zap.NewProductionConfig() | |
| cfg.Encoding = "json" | |
| cfg.OutputPaths = []string{ | |
| "/tmp/logs", | |
| } | |
| rawJSON := []byte(`{ | |
| "level": "debug", | |
| "encoding": "json", | |
| "outputPaths": ["stdout", "/tmp/logs"], | |
| "errorOutputPaths": ["stderr"], | |
| "initialFields": {"foo": "bar"}, | |
| "encoderConfig": { | |
| "messageKey": "message", | |
| "levelKey": "level", | |
| "levelEncoder": "lowercase" | |
| } | |
| }`) | |
| if err := json.Unmarshal(rawJSON, &cfg); err != nil { | |
| panic(err) | |
| } | |
| logger, err := cfg.Build() | |
| if err != nil { | |
| panic(err) | |
| } | |
| defer logger.Sync() | |
| logger.Info("logger construction succeeded") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment