diff --git a/README.md b/README.md index 1c20634..6712248 100644 --- a/README.md +++ b/README.md @@ -3,29 +3,38 @@ `log` is an out-of-the-box logger, it wraps [zap](https://github.com/uber-go/zap) and makes it simpler to use. +## Install + +```sh +$ go get github.com/juan-chan/log@latest +``` + + ## Example ```go -Info("Hello, World!") -Warn("Hello, Warning!") -Error("nil pointer dereference", ErrorField(errors.New("NPE"))) -Error("some error", ErrorStr(errors.New("what's wrong"))) -Infof("Today is %s, so happy!", "Friday") -Debug("This log should not be displayed") -SetDebug() -Debug("This log should be displayed") -SetLevel(ErrorLevel) -Info("This log should not be displayed") -Warn("This log should not be displayed") +import "github.com/juan-chan/log" + +log.Info("Hello, World!") +log.Warn("Hello, Warning!") +log.Error("nil pointer dereference", ErrorField(errors.New("NPE"))) +log.Error("some error", ErrorStr(errors.New("what's wrong"))) +log.Infof("Today is %s, so happy!", "Friday") +log.Debug("This log should not be displayed") +log.SetDebug() +log.Debug("This log should be displayed") +log.SetLevel(ErrorLevel) +log.Info("This log should not be displayed") +log.Warn("This log should not be displayed") logger, _ := New(&Config{Encoding: "console"}) -ReplaceLogger(logger) -SetLevel(InfoLevel) -Infof("What's your name? My name is %s", "Chan") -Error("illegal argument error", String("arg", "name")) +log.ReplaceLogger(logger) +log.SetLevel(InfoLevel) +log.Infof("What's your name? My name is %s", "Chan") +log.Error("illegal argument error", String("arg", "name")) ``` -输出: +Output: ```text {"level":"info","time":"2022-11-16 14:09:47.848","caller":"log/logger_test.go:9","msg":"Hello, World!"} @@ -37,7 +46,7 @@ Error("illegal argument error", String("arg", "name")) 2022-11-16 14:09:47.848 INFO log/logger_test.go:24 What's your name? My name is Chan 2022-11-16 14:09:47.848 ERROR log/logger_test.go:25 illegal argument error {"arg": "name"} github.com/juan-chan/log.TestLogger - /Users/chenxinyu/Workspace/go/coding/log-github/log/logger_test.go:25 + /Users/chan/Workspace/go/log/logger_test.go:25 testing.tRunner /usr/local/go/src/testing/testing.go:1446 ``` @@ -45,4 +54,4 @@ testing.tRunner ## Sentry -`log` supports sentry by default, you just need to set an environment variable named: `SENTRY_DSN` and `log` will add a hook for it. +`log` supports [sentry](https://sentry.io/) by default, you just need to set an environment variable named: `SENTRY_DSN` and `log` will add a hook for it.