Created
October 25, 2018 21:58
-
-
Save svishwanath-tw/36e428713c51aad1adc4e43ce97e859d to your computer and use it in GitHub Desktop.
sampleZapLumberJackIntegration.go
This file contains 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 ( | |
"fmt" | |
"time" | |
"go.uber.org/zap" | |
"go.uber.org/zap/zapcore" | |
"gopkg.in/natefinch/lumberjack.v2" | |
) | |
func main() { | |
fmt.Println("Hello world!!") | |
w := zapcore.AddSync(&lumberjack.Logger{ | |
Filename: "/tmp/lumberjackedd_zap.log", | |
MaxSize: 5, // megabytes | |
MaxBackups: 4, | |
MaxAge: 7, | |
Compress: false, | |
}) | |
core := zapcore.NewCore( | |
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), | |
w, | |
zap.InfoLevel, | |
) | |
logger := zap.New(core) | |
defer logger.Sync() | |
url := "http://google.com" | |
logger.Info("failed to fetch URL", | |
// Structured context as strongly typed Field values. | |
zap.String("url", url), | |
zap.Int("attempt", 3), | |
zap.Duration("backoff", time.Second), | |
) | |
str := `This is a long string. | |
This is a long string. | |
This is a long string. | |
This is a long string. | |
This is a long string. | |
This is a long string. | |
This is a long string. | |
This is a long string. | |
` | |
for i := 1; i <= 50000; i++ { | |
logger.Info(str) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment