Skip to content

Instantly share code, notes, and snippets.

@bbengfort
Created March 20, 2017 20:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbengfort/b9345330339dee7fc04d6153b1a2eb91 to your computer and use it in GitHub Desktop.
Save bbengfort/b9345330339dee7fc04d6153b1a2eb91 to your computer and use it in GitHub Desktop.
No-op logger to turn off logging in Go without too much of a performance hit.
package noplog
import "log"
var noplog = &NopLogger{
log.New(NullWriter(1), "", log.LstdFlags),
}
// NullWriter implements the io.Write interface but doesn't do anything.
type NullWriter int
// Write implements the io.Write interface but is a noop.
func (NullWriter) Write([]byte) (int, error) { return 0, nil }
// NopLogger is a noop logger for passing to grpclog to minimize spew.
type NopLogger struct {
*log.Logger
}
// Fatal is a noop
func (l *NopLogger) Fatal(args ...interface{}) {}
// Fatalf is a noop
func (l *NopLogger) Fatalf(format string, args ...interface{}) {}
// Fatalln is a noop
func (l *NopLogger) Fatalln(args ...interface{}) {}
// Print is a noop
func (l *NopLogger) Print(args ...interface{}) {}
// Printf is a noop
func (l *NopLogger) Printf(format string, args ...interface{}) {}
// Println is a noop
func (l *NopLogger) Println(v ...interface{}) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment