GopherSnippetsStar

Code snippets with tests and testable examples for the Go programming language

How to disable log output

Snippets Index - Run code on Go playground - Edit

package main

import (
	"io/ioutil"
	"log"
)

func Example() {
	// If you want to disable log output (during test for example)
	// you have to set the logger ouput to ioutil.Discard
	// which is an io.Writer on which all Write calls succeed
	// without doing anything
	log.SetOutput(ioutil.Discard)
	log.Println("log disabled")
	// Output:
	//
}

by psampaz - source code - comment below or here