From 1e09ffc8a13eca460df11dfcab6dc8d3a4a411c4 Mon Sep 17 00:00:00 2001 From: cxy77 Date: Wed, 16 Nov 2022 14:15:29 +0800 Subject: [PATCH] update --- README.md | 31 ++++++++++++++++++------------- go.mod | 9 ++++++--- go.sum | 10 ++++++++++ 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f6f1b92..1c20634 100644 --- a/README.md +++ b/README.md @@ -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!") @@ -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. diff --git a/go.mod b/go.mod index e7dd817..32c78d9 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 4787782..680ae1c 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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=