Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
reedchan7 committed Nov 16, 2022
1 parent 1e09ffc commit d116838
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!"}
Expand All @@ -37,12 +46,12 @@ 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
```


## 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.

0 comments on commit d116838

Please sign in to comment.