Created
March 20, 2017 20:42
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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