Go의 로그인 라이브러리 zap 정보
이른바
거의 제목과 마찬가지로 고의 제3자가 만든 로그 라이브러리다.
zap에 관하여 특징과 기본적인 사용 방법을 총결하였다.
컨디션
특징.
sync.Pool에서 이 위치를 피했다.
Logger와 Sugared Logger의 차이점
샘플 코드
logger, _ := zap.NewProduction()
defer logger.Sync()
url := "https://example.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),
)
결과{"level":"info","ts":1633150860.2312949,"caller":"zap-example/main.go:13","msg":"failed to fetch URL","url":"https://example.com/","attempt":3,"backoff":"1"}
logger, _ := zap.NewProduction()
defer logger.Sync() // flushes buffer, if any
sugar := logger.Sugar()
url := "https://example.com/"
sugar.Infow("failed to fetch URL",
// Structured context as loosely typed key-value pairs.
"url", url,
"attempt", 3,
"backoff", time.Second,
)
sugar.Infof("Failed to fetch URL: %s", url)
결과{"level":"info","ts":1633151590.2312949,"caller":"zap-example/main.go:13","msg":"failed to fetch URL","url":"https://example.com/","attempt":3,"backoff":"1"}
{"level":"info","ts":1633151590.232893,"caller":"zap-example/main.go:19","msg":"failed to fetch URL: https://example.com/"}
총결산
Go의 Logging 라이브러리 zap에 대해 설명합니다.
아무래도 속도를 의식할 때 Logger를 사용하고, 그 외에 기본적으로 Sugared Logger를 사용하면 문제없다.
또 다른 Config 놀이가 있다면 로그를 맞춤형으로 만들 수 있지만 기회가 된다면 글을 쓰고 싶습니다.
참고 문헌
Reference
이 문제에 관하여(Go의 로그인 라이브러리 zap 정보), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/mima/articles/069b223d9b221f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)