8000 Undocumented duplicate key handling & With? · Issue #151 · hashicorp/go-hclog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Undocumented duplicate key handling & With? #151
Open
@ggambetti

Description

@ggambetti

It appears that With has undocumented and inconsistent behaviour around it's handling of extra parameters depending on the output format being used.

I've built a test case that showcases the behaviour for the plain logger output:

	t.Run("multiple unpaired with/plain", func(t *testing.T) {
		var buf bytes.Buffer

		rootLogger := New(&LoggerOptions{
			Name:   "with_with_test",
			Output: &buf,
		})

		derived1 := rootLogger.With("a").With("b")
		derived1.Info("test1")
		output := buf.String()
		dataIdx := strings.IndexByte(output, ' ')
		assert.Equal(t, "[INFO]  with_with_test: test1: EXTRA_VALUE_AT_END=a EXTRA_VALUE_AT_END=b\n", output[dataIdx+1:])
	})

	t.Run("multiple unpaired with/json", func(t *testing.T) {
		var buf bytes.Buffer

		rootLogger := New(&LoggerOptions{
			Name:       "with_with_json_test",
			JSONFormat: true,
			Output:     &buf,
		})

		derived1 := rootLogger.With("a").With("b")
		derived1.Info("test1")

		var raw map[string]interface{}
		if err := json.Unmarshal(buf.Bytes(), &raw); err != nil {
			t.Fatal(err)
		}
		assert.Equal(t, "b", raw[MissingKey])
	})

This behaviour differs between the JSON and plain output formats, as JSON converts the arguments into a map (destroying multiple instances of EXTRA_VALUE_AT_END) while plain does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0