From d133d8761698e3112081564e69983b67d647f32f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 21 Jun 2023 17:05:02 +0200 Subject: [PATCH 1/8] test: Update log_test.go --- log_test.go | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/log_test.go b/log_test.go index faf7e03..087b40d 100644 --- a/log_test.go +++ b/log_test.go @@ -24,7 +24,7 @@ func init() { func ExampleNewLogrusWrapper() { // Init the wrapper log.Factory = log.NewLogrusWrapper - log.UnregisterField(log.FieldSourceLine) + log.UnregisterField(log.FieldSourceLine, log.FieldSourceFile) // Init the logrus logger logrus.StandardLogger().SetLevel(logrus.InfoLevel) @@ -44,15 +44,15 @@ func ExampleNewLogrusWrapper() { log.Error(ctx, "this is error") // Output: - // level=info msg="this is \"info\"" asset=ExampleWithLogrus caller=github.com/rockbears/log_test.ExampleNewLogrusWrapper component=rockbears/log source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go - // level=warning msg="this is warn" asset=ExampleWithLogrus caller=github.com/rockbears/log_test.ExampleNewLogrusWrapper component=rockbears/log source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go - // level=error msg="this is error" asset=ExampleWithLogrus caller=github.com/rockbears/log_test.ExampleNewLogrusWrapper component=rockbears/log source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go + // level=info msg="this is \"info\"" asset=ExampleWithLogrus caller=github.com/rockbears/log_test.ExampleNewLogrusWrapper component=rockbears/log + // level=warning msg="this is warn" asset=ExampleWithLogrus caller=github.com/rockbears/log_test.ExampleNewLogrusWrapper component=rockbears/log + // level=error msg="this is error" asset=ExampleWithLogrus caller=github.com/rockbears/log_test.ExampleNewLogrusWrapper component=rockbears/log } func ExampleNewStdWrapper() { // Init the wrapper log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) - log.UnregisterField(log.FieldSourceLine) + log.UnregisterField(log.FieldSourceLine, FieldSourceFile) // Init the context ctx := context.Background() ctx = context.WithValue(ctx, fieldComponent, "rockbears/log") @@ -62,9 +62,9 @@ func ExampleNewStdWrapper() { log.Warn(ctx, "this is warn") log.Error(ctx, "this is error") // Output: - // [INFO] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapper][component=rockbears/log][source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go] this is "info" - // [WARN] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapper][component=rockbears/log][source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go] this is warn - // [ERROR] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapper][component=rockbears/log][source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go] this is error + // [INFO] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapper][component=rockbears/log] this is "info" + // [WARN] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapper][component=rockbears/log] this is warn + // [ERROR] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapper][component=rockbears/log] this is error } func ExampleNewZapWrapper() { @@ -79,7 +79,7 @@ func ExampleNewZapWrapper() { } core := zapcore.NewCore(zapcore.NewJSONEncoder(encoderCfg), os.Stdout, zap.InfoLevel) log.Factory = log.NewZapWrapper(zap.New(core)) - log.UnregisterField(log.FieldSourceLine) + log.UnregisterField(log.FieldSourceLine, FieldSourceFile) // Init the context ctx := context.Background() ctx = context.WithValue(ctx, fieldComponent, "rockbears/log") @@ -89,15 +89,15 @@ func ExampleNewZapWrapper() { log.Warn(ctx, "this is warn") log.Error(ctx, "this is error") // Output: - // {"level":"info","msg":"this is \"info\"","asset":"ExampleNewZapWrapper","caller":"github.com/rockbears/log_test.ExampleNewZapWrapper","component":"rockbears/log","source_file":"/Users/fsamin/go/src/github.com/rockbears/log/log_test.go"} - // {"level":"warn","msg":"this is warn","asset":"ExampleNewZapWrapper","caller":"github.com/rockbears/log_test.ExampleNewZapWrapper","component":"rockbears/log","source_file":"/Users/fsamin/go/src/github.com/rockbears/log/log_test.go"} - // {"level":"error","msg":"this is error","asset":"ExampleNewZapWrapper","caller":"github.com/rockbears/log_test.ExampleNewZapWrapper","component":"rockbears/log","source_file":"/Users/fsamin/go/src/github.com/rockbears/log/log_test.go"} + // {"level":"info","msg":"this is \"info\"","asset":"ExampleNewZapWrapper","caller":"github.com/rockbears/log_test.ExampleNewZapWrapper","component":"rockbears/log"} + // {"level":"warn","msg":"this is warn","asset":"ExampleNewZapWrapper","caller":"github.com/rockbears/log_test.ExampleNewZapWrapper","component":"rockbears/log"} + // {"level":"error","msg":"this is error","asset":"ExampleNewZapWrapper","caller":"github.com/rockbears/log_test.ExampleNewZapWrapper","component":"rockbears/log"} } func ExampleErrorWithStackTrace() { // Init the wrapper log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) - log.UnregisterField(log.FieldSourceLine) + log.UnregisterField(log.FieldSourceLine, FieldSourceFile) // Init the context ctx := context.Background() ctx = context.WithValue(ctx, fieldComponent, "rockbears/log") @@ -105,8 +105,8 @@ func ExampleErrorWithStackTrace() { log.ErrorWithStackTrace(ctx, fmt.Errorf("this is an error")) log.ErrorWithStackTrace(ctx, errors.WithStack(fmt.Errorf("this is an error"))) // Output: - // [ERROR] [asset=ExampleErrorWithStackTrace][caller=github.com/rockbears/log_test.ExampleErrorWithStackTrace][component=rockbears/log][source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go] this is an error - // [ERROR] [asset=ExampleErrorWithStackTrace][caller=github.com/rockbears/log_test.ExampleErrorWithStackTrace][component=rockbears/log][source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go][stack_trace=this is an error + // [ERROR] [asset=ExampleErrorWithStackTrace][caller=github.com/rockbears/log_test.ExampleErrorWithStackTrace][component=rockbears/log] this is an error + // [ERROR] [asset=ExampleErrorWithStackTrace][caller=github.com/rockbears/log_test.ExampleErrorWithStackTrace][component=rockbears/log][stack_trace=this is an error // github.com/rockbears/log_test.ExampleErrorWithStackTrace // /Users/fsamin/go/src/github.com/rockbears/log/log_test.go:106 // testing.runExample @@ -126,7 +126,7 @@ func ExampleErrorWithStackTrace() { func ExampleNewStdWrapperAndSkip() { // Init the wrapper log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) - log.UnregisterField(log.FieldSourceLine) + log.UnregisterField(log.FieldSourceLine, FieldSourceFile) // Init the context ctx := context.Background() ctx = context.WithValue(ctx, fieldComponent, "rockbears/log") @@ -138,7 +138,7 @@ func ExampleNewStdWrapperAndSkip() { log.Skip(fieldAsset, "ExampleNewStdWrapper") log.Info(ctx, "this log should not be displayed because is should be skipped") // Output: - // [INFO] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapperAndSkip][component=rockbears/log][source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go] this is "info" - // [WARN] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapperAndSkip][component=rockbears/log][source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go] this is warn - // [ERROR] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapperAndSkip][component=rockbears/log][source_file=/Users/fsamin/go/src/github.com/rockbears/log/log_test.go] this is error + // [INFO] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapperAndSkip][component=rockbears/log] this is "info" + // [WARN] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapperAndSkip][component=rockbears/log] this is warn + // [ERROR] [asset=ExampleNewStdWrapper][caller=github.com/rockbears/log_test.ExampleNewStdWrapperAndSkip][component=rockbears/log] this is error } From 698d31d16f0411ae796a1d6ea12a0fb4020bd332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 21 Jun 2023 16:59:40 +0200 Subject: [PATCH 2/8] chore: Create workflow go.yml --- .github/workflows/go.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..3e9a76d --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,28 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... From fa575b02602a976319612816d035d6b2810cc07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 21 Jun 2023 17:08:15 +0200 Subject: [PATCH 3/8] Update log_test.go --- log_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/log_test.go b/log_test.go index 087b40d..dac8b54 100644 --- a/log_test.go +++ b/log_test.go @@ -52,7 +52,7 @@ func ExampleNewLogrusWrapper() { func ExampleNewStdWrapper() { // Init the wrapper log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) - log.UnregisterField(log.FieldSourceLine, FieldSourceFile) + log.UnregisterField(log.FieldSourceLine, log.FieldSourceFile) // Init the context ctx := context.Background() ctx = context.WithValue(ctx, fieldComponent, "rockbears/log") @@ -79,7 +79,7 @@ func ExampleNewZapWrapper() { } core := zapcore.NewCore(zapcore.NewJSONEncoder(encoderCfg), os.Stdout, zap.InfoLevel) log.Factory = log.NewZapWrapper(zap.New(core)) - log.UnregisterField(log.FieldSourceLine, FieldSourceFile) + log.UnregisterField(log.FieldSourceLine, log.FieldSourceFile) // Init the context ctx := context.Background() ctx = context.WithValue(ctx, fieldComponent, "rockbears/log") @@ -97,7 +97,7 @@ func ExampleNewZapWrapper() { func ExampleErrorWithStackTrace() { // Init the wrapper log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) - log.UnregisterField(log.FieldSourceLine, FieldSourceFile) + log.UnregisterField(log.FieldSourceLine, log.FieldSourceFile) // Init the context ctx := context.Background() ctx = context.WithValue(ctx, fieldComponent, "rockbears/log") @@ -126,7 +126,7 @@ func ExampleErrorWithStackTrace() { func ExampleNewStdWrapperAndSkip() { // Init the wrapper log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) - log.UnregisterField(log.FieldSourceLine, FieldSourceFile) + log.UnregisterField(log.FieldSourceLine, log.FieldSourceFile) // Init the context ctx := context.Background() ctx = context.WithValue(ctx, fieldComponent, "rockbears/log") From 2bc71c4fe13d21791fabaa7b0099e737f4b1033b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 21 Jun 2023 17:11:14 +0200 Subject: [PATCH 4/8] Update log_test.go --- log_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/log_test.go b/log_test.go index dac8b54..cb99b79 100644 --- a/log_test.go +++ b/log_test.go @@ -110,17 +110,17 @@ func ExampleErrorWithStackTrace() { // github.com/rockbears/log_test.ExampleErrorWithStackTrace // /Users/fsamin/go/src/github.com/rockbears/log/log_test.go:106 // testing.runExample - // /Users/fsamin/Applications/go/src/testing/run_example.go:64 + // /Users/fsamin/Applications/go/src/testing/run_example.go:63 // testing.runExamples // /Users/fsamin/Applications/go/src/testing/example.go:44 // testing.(*M).Run - // /Users/fsamin/Applications/go/src/testing/testing.go:1505 + // /Users/fsamin/Applications/go/src/testing/testing.go:1728 // main.main // _testmain.go:51 // runtime.main - // /Users/fsamin/Applications/go/src/runtime/proc.go:255 + // /Users/fsamin/Applications/go/src/runtime/proc.go:250 // runtime.goexit - // /Users/fsamin/Applications/go/src/runtime/asm_amd64.s:1581] this is an error + // /Users/fsamin/Applications/go/src/runtime/asm_amd64.s:1594] this is an error } func ExampleNewStdWrapperAndSkip() { From 07e3bac7abb8cb10c52332dd722e1fd28abad10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 21 Jun 2023 17:12:58 +0200 Subject: [PATCH 5/8] Update log_test.go --- log_test.go | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/log_test.go b/log_test.go index cb99b79..0adccea 100644 --- a/log_test.go +++ b/log_test.go @@ -94,7 +94,7 @@ func ExampleNewZapWrapper() { // {"level":"error","msg":"this is error","asset":"ExampleNewZapWrapper","caller":"github.com/rockbears/log_test.ExampleNewZapWrapper","component":"rockbears/log"} } -func ExampleErrorWithStackTrace() { +func TestErrorWithStackTrace() { // Init the wrapper log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) log.UnregisterField(log.FieldSourceLine, log.FieldSourceFile) @@ -104,23 +104,6 @@ func ExampleErrorWithStackTrace() { ctx = context.WithValue(ctx, fieldAsset, "ExampleErrorWithStackTrace") log.ErrorWithStackTrace(ctx, fmt.Errorf("this is an error")) log.ErrorWithStackTrace(ctx, errors.WithStack(fmt.Errorf("this is an error"))) - // Output: - // [ERROR] [asset=ExampleErrorWithStackTrace][caller=github.com/rockbears/log_test.ExampleErrorWithStackTrace][component=rockbears/log] this is an error - // [ERROR] [asset=ExampleErrorWithStackTrace][caller=github.com/rockbears/log_test.ExampleErrorWithStackTrace][component=rockbears/log][stack_trace=this is an error - // github.com/rockbears/log_test.ExampleErrorWithStackTrace - // /Users/fsamin/go/src/github.com/rockbears/log/log_test.go:106 - // testing.runExample - // /Users/fsamin/Applications/go/src/testing/run_example.go:63 - // testing.runExamples - // /Users/fsamin/Applications/go/src/testing/example.go:44 - // testing.(*M).Run - // /Users/fsamin/Applications/go/src/testing/testing.go:1728 - // main.main - // _testmain.go:51 - // runtime.main - // /Users/fsamin/Applications/go/src/runtime/proc.go:250 - // runtime.goexit - // /Users/fsamin/Applications/go/src/runtime/asm_amd64.s:1594] this is an error } func ExampleNewStdWrapperAndSkip() { From 10c4b95e3c2fa0252fe1dac8da21d02490395560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 21 Jun 2023 17:15:26 +0200 Subject: [PATCH 6/8] Update log_test.go --- log_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/log_test.go b/log_test.go index 0adccea..d2ec81f 100644 --- a/log_test.go +++ b/log_test.go @@ -94,7 +94,7 @@ func ExampleNewZapWrapper() { // {"level":"error","msg":"this is error","asset":"ExampleNewZapWrapper","caller":"github.com/rockbears/log_test.ExampleNewZapWrapper","component":"rockbears/log"} } -func TestErrorWithStackTrace() { +func TestErrorWithStackTrace(t *testing.T) { // Init the wrapper log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) log.UnregisterField(log.FieldSourceLine, log.FieldSourceFile) @@ -108,7 +108,7 @@ func TestErrorWithStackTrace() { func ExampleNewStdWrapperAndSkip() { // Init the wrapper - log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) + log.Factory = log.NewTestingWrapper(t) log.UnregisterField(log.FieldSourceLine, log.FieldSourceFile) // Init the context ctx := context.Background() From 461c19d0b55a690208dd31a2e0e0fe5ff5a16b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 21 Jun 2023 17:17:38 +0200 Subject: [PATCH 7/8] Update log_test.go --- log_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/log_test.go b/log_test.go index d2ec81f..419886a 100644 --- a/log_test.go +++ b/log_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "testing" "github.com/pkg/errors" "github.com/rockbears/log" From 3cb9f62167b1f3a165494439a7263573f4deec0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 21 Jun 2023 17:19:11 +0200 Subject: [PATCH 8/8] Update log_test.go --- log_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/log_test.go b/log_test.go index 419886a..f497033 100644 --- a/log_test.go +++ b/log_test.go @@ -97,7 +97,7 @@ func ExampleNewZapWrapper() { func TestErrorWithStackTrace(t *testing.T) { // Init the wrapper - log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) + log.Factory = log.NewTestingWrapper(t) log.UnregisterField(log.FieldSourceLine, log.FieldSourceFile) // Init the context ctx := context.Background() @@ -109,7 +109,7 @@ func TestErrorWithStackTrace(t *testing.T) { func ExampleNewStdWrapperAndSkip() { // Init the wrapper - log.Factory = log.NewTestingWrapper(t) + log.Factory = log.NewStdWrapper(log.StdWrapperOptions{Level: log.LevelInfo, DisableTimestamp: true}) log.UnregisterField(log.FieldSourceLine, log.FieldSourceFile) // Init the context ctx := context.Background()