Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: nested group name was wrong in Err attribute #44

Closed
missedone opened this issue Sep 29, 2023 · 2 comments · Fixed by #45
Closed

bug: nested group name was wrong in Err attribute #44

missedone opened this issue Sep 29, 2023 · 2 comments · Fixed by #45
Assignees
Labels
bug Something isn't working

Comments

@missedone
Copy link

	logger = logger.WithGroup("group0").With("reqId", "xxxx-xxx-xxxx-xxxx")
	logger.WithGroup("group1").Debug("Debug msg", "foo", "bar", "x", "y")
	logger.Info("This is a info msg", "foo", 1, "bar", true)
	logger.Warn("This is a warn msg", "foo", map[string]string{"aa": "bb", "cc": "dd"}, "bar", []string{"a", "b", "c"}, "null response", nil)
	logger.Error("This is a error msg", tint.Err(errors.New("i'm an error")))

the expected output should be group0.group1.err
image

@lmittmann
Copy link
Owner

I can not reproduce this issue with your code. Are you using the latest version of tint (v1.0.2)?

@missedone
Copy link
Author

yes, i'm using v1.0.2

here is the whole code

package logging

import (
	"errors"
	"log/slog"
	"os"
	"testing"
	"time"

	"github.com/lmittmann/tint"
)

func TestLogging(t *testing.T) {
	lh := tint.NewHandler(os.Stdout, &tint.Options{
		Level:      slog.LevelDebug,
		TimeFormat: time.Kitchen,
		AddSource:  true,
	})

	logger := slog.New(lh)
	slog.SetDefault(logger)

	logger = logger.WithGroup("group0").With("reqId", "xxxx-xxx-xxxx-xxxx")
	logger.WithGroup("group1").Debug("Debug msg", "foo", "bar", "x", "y")
	logger.Info("This is a info msg", "foo", 1, "bar", true)
	logger.Warn("This is a warn msg", "foo", map[string]string{"aa": "bb", "cc": "dd"}, "bar", []string{"a", "b", "c"}, "null response", nil)
	logger.Error("This is a error msg", tint.Err(errors.New("i'm an error")))
}

@lmittmann lmittmann added the bug Something isn't working label Sep 29, 2023
@lmittmann lmittmann self-assigned this Oct 3, 2023
lmittmann added a commit that referenced this issue Oct 3, 2023
lmittmann added a commit that referenced this issue Oct 3, 2023
* added test case

* fixed #44

---------

Co-authored-by: lmittmann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants