Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
reedchan7 committed Nov 16, 2022
1 parent 0c66a0c commit 1e09ffc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# log

`log` 是一个基于 [zap](https://github.com/uber-go/zap) 封装的一个简单的日志库,开箱即用。
`log` is an out-of-the-box logger, it wraps [zap](https://github.com/uber-go/zap) and makes it simpler to use.


## 示例
## Example

```go
Info("Hello, World!")
Expand All @@ -28,16 +28,21 @@ Error("illegal argument error", String("arg", "name"))
输出:

```text
{"level":"info","time":"2022-11-11 13:26:43.890","caller":"log/logger_test.go:9","msg":"Hello, World!"}
{"level":"warn","time":"2022-11-11 13:26:43.890","caller":"log/logger_test.go:10","msg":"Hello, Warning!"}
{"level":"error","time":"2022-11-11 13:26:43.890","caller":"log/logger_test.go:11","msg":"nil pointer dereference","error":"NPE","stacktrace":"e.coding.net/coding-artifacts/log.TestLogger\n\t/Users/chenxinyu/Workspace/go/coding/log/logger_test.go:11\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1446"}
{"level":"error","time":"2022-11-11 13:26:43.890","caller":"log/logger_test.go:12","msg":"some error","error":"what's wrong","stacktrace":"e.coding.net/coding-artifacts/log.TestLogger\n\t/Users/chenxinyu/Workspace/go/coding/log/logger_test.go:12\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1446"}
{"level":"info","time":"2022-11-11 13:26:43.890","caller":"log/logger_test.go:13","msg":"Today is Friday, so happy!"}
{"level":"debug","time":"2022-11-11 13:26:43.890","caller":"log/logger_test.go:16","msg":"This log should be displayed"}
2022-11-11 13:26:43.891 INFO log/logger_test.go:24 What's your name? My name is Chan
2022-11-11 13:38:35.483 ERROR log/logger_test.go:25 illegal argument error {"arg": "name"}
e.coding.net/coding-artifacts/log.TestLogger
/Users/chenxinyu/Workspace/go/coding/log/logger_test.go:25
{"level":"info","time":"2022-11-16 14:09:47.848","caller":"log/logger_test.go:9","msg":"Hello, World!"}
{"level":"warn","time":"2022-11-16 14:09:47.848","caller":"log/logger_test.go:10","msg":"Hello, Warning!"}
{"level":"error","time":"2022-11-16 14:09:47.848","caller":"log/logger_test.go:11","msg":"nil pointer dereference","error":"NPE","stacktrace":"github.com/juan-chan/log.TestLogger\n\t/Users/chenxinyu/Workspace/go/coding/log-github/log/logger_test.go:11\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1446"}
{"level":"error","time":"2022-11-16 14:09:47.848","caller":"log/logger_test.go:12","msg":"some error","error":"what's wrong","stacktrace":"github.com/juan-chan/log.TestLogger\n\t/Users/chenxinyu/Workspace/go/coding/log-github/log/logger_test.go:12\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1446"}
{"level":"info","time":"2022-11-16 14:09:47.848","caller":"log/logger_test.go:13","msg":"Today is Friday, so happy!"}
{"level":"debug","time":"2022-11-16 14:09:47.848","caller":"log/logger_test.go:16","msg":"This log should be displayed"}
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
testing.tRunner
/usr/local/go/src/testing/testing.go:1446
/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.
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module e.codingcorp.net/devops/coding-artifacts/log
module github.com/juan-chan/log

go 1.19

require (
github.com/TheZeroSlave/zapsentry v1.12.0 // indirect
github.com/TheZeroSlave/zapsentry v1.12.0
go.uber.org/zap v1.23.0
)

require (
github.com/getsentry/sentry-go v0.15.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
github.com/TheZeroSlave/zapsentry v1.12.0 h1:hhfwvD7pQbnCIOvAEGM4NXLiaX4b6W6ZWNtL6awSBGc=
github.com/TheZeroSlave/zapsentry v1.12.0/go.mod h1:00uO/VpPrSJG/XigAfTi0F4WMFIw2DmP/IDVUhPBvNw=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/getsentry/sentry-go v0.15.0 h1:CP9bmA7pralrVUedYZsmIHWpq/pBtXTSew7xvVpfLaA=
github.com/getsentry/sentry-go v0.15.0/go.mod h1:RZPJKSw+adu8PBNygiri/A98FqVr2HtRckJk9XVxJ9I=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
Expand All @@ -22,3 +31,4 @@ golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 comments on commit 1e09ffc

Please sign in to comment.