Skip to content

Commit

Permalink
简单测试了zaplog,明白大概怎么用
Browse files Browse the repository at this point in the history
  • Loading branch information
peifengll committed Dec 11, 2023
1 parent c4acc1c commit 1361944
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions testzap/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"time"

"go.uber.org/zap"
)

func main() {
logger := zap.NewExample()
defer logger.Sync()

url := "http://example.org/api"
logger.Info("failed to fetch URL",
zap.String("url", url),
zap.Int("attempt", 3),
zap.Duration("backoff", time.Second),
)

sugar := logger.Sugar()
sugar.Infow("failed to fetch URL",
"url", url,
"attempt", 3,
"backoff", time.Second,
)
sugar.Infof("Failed to fetch URL: %s", url)
}

0 comments on commit 1361944

Please sign in to comment.