If you are using zap as your logging tool, then when you write the tests, you might want to assert the function via the logs. You can use zap/observer package to make it possible.

Below is a code piece to demonstrate how it works:

package main

import (


func LogHello(name string) {
	zap.L().Info("hello: " + name)

func TestLogHello(t *testing.T) {
	// arrange
	core, recordedLogs := observer.New(zapcore.InfoLevel)

	// act

	// assert
	gotLog := recordedLogs.All()[0].Message
	if gotLog != "hello: Jerry" {
		t.Errorf("LogHello(\"Jerry\") = %s; want: `hello: Jerry`", gotLog)

	t.Logf("%+v\n", recordedLogs.All())

goplayground url: https://play.golang.org/p/7olsFLGF6aZ