0
0

go-awslambda

Posted at
--- FAIL: TestSlogtest (0.03s)
    \zapslog\logger.go:130: 	message
    \zapslog\logger.go:130: 	INFO	message	{"k": "v"}
    \zapslog\logger.go:130: 	msg	{"a": "b", "c": "d"}
    \zapslog\logger.go:130: INFO	msg	{"k": "v"}
    \zapslog\logger.go:130: 	msg	{"a": "b", "k": "v"}
    \zapslog\logger.go:130: 	msg	{"a": "b", "G": {"c": "d"}, "e": "f"}
    \zapslog\logger.go:130: 	msg	{"a": "b", "e": "f"}
    \zapslog\logger.go:130: 	msg	{"a": "b", "c": "d", "e": "f"}
    \zapslog\logger.go:130: 	a Handler should inline the Attrs of a group with an empty key	{"a": "b"}
    \zapslog\logger.go:130: 	a Handler should handle multiple WithGroup and WithAttr calls	{"a": "b", "G": {"c": "d", "e": "f"}}
    \zapslog\logger.go:130: 	msg	{"a": "b", "G": {"c": "d"}}
    \zapslog\logger.go:130: 	msg	{"k": "replaced"}
    \zapslog\logger.go:130: 	msg	{"G": {"a": "v1", "b": "v2"}}
    \zapslog\logger.go:130: 	msg	{"k": "replaced"}
    \zapslog\logger.go:130: 	msg	{"G": {"a": "v1", "b": "v2"}}
{"G": {"a": "b"}}
{"a": "b", "G": {"c": "d", "H": {"e": "f"}}}
aaa.go
// WithAttrs returns a new Handler whose attributes consist of
// both the receiver's attributes and the arguments.
func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler {
	var cloned Handler

	if h.holdGroup != "" {
		handler := h.withFields(zap.Namespace(h.holdGroup))
		cloned = *handler
	} else {
		cloned = *h
	}
	cloned.holdGroup = ""

	fields := make([]zapcore.Field, 0, len(attrs))
	for _, attr := range attrs {
		fields = append(fields, convertAttrToField(attr))
	}
	return (&cloned).withFields(fields...)
}

// WithGroup returns a new Handler with the given group appended to
// the receiver's existing groups.
func (h *Handler) WithGroup(group string) slog.Handler {
	var cloned Handler

	if h.holdGroup != "" {
		handler := h.withFields(zap.Namespace(h.holdGroup))
		cloned = *handler
	} else {
		cloned = *h
	}
	cloned.holdGroup = group
	return &cloned
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0