Skip to content

testlog print error file info #5093

@Iceber

Description

@Iceber

Description

https://github.com/containerd/containerd/runs/1984545869?check_suite_focus=true#step:8:296

Steps to reproduce the issue:

  1. use logtest.WithT to handle testing.TB
  2. use log.G(ctx) print log

https://github.com/Iceber/containerd/blob/logtest/log/logtest/context_test.go

func TestLogTest(t *testing.T) {
        ctx := WithT(context.Background(), t)
        log.G(ctx).Info("log info")
}

Describe the results you received:
https://github.com/containerd/containerd/blob/master/snapshots/devmapper/snapshotter.go#L360

        log_hook.go:40 time="2021-02-26T03:15:15.069823052Z" level=debug msg="creating new thin device 'containerd-snapshotter-suite-pool-961076009-snap-1'"

Print log_hook.go:40 instead of the name of the file info that called log.G(ctx).Debug

Describe the results you expected:

        snapshotter.go:360 time="2021-02-26T03:15:15.069823052Z" level=debug msg="creating new thin device 'containerd-snapshotter-suite-pool-961076009-snap-1'"

Output of containerd --version:

(paste your output here)

Any other relevant information:
https://github.com/containerd/containerd/blob/master/log/logtest/log_hook.go#L35

func (h *testHook) Fire(e *logrus.Entry) error {
	s, err := h.fmt.Format(e)
	if err != nil {
		return err
	}
	h.t.Log(string(bytes.TrimRight(s, "\n")))
	return nil
}

The reason is that the t.Log is called in the logrus hook, so the information about the calling function and the file is printed

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions