Created
November 28, 2018 11:48
-
-
Save tierpod/554363fd9a80ffc2cdc4400263c3576e to your computer and use it in GitHub Desktop.
Configure logger in go with logutils
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
func setupLog(debug, datetime bool) { | |
filter := &logutils.LevelFilter{ | |
Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"}, | |
MinLevel: logutils.LogLevel("INFO"), | |
Writer: os.Stdout, | |
} | |
if debug { | |
filter.MinLevel = logutils.LogLevel("DEBUG") | |
} | |
if datetime { | |
log.SetFlags(log.LstdFlags) | |
} else { | |
log.SetFlags(0) | |
} | |
log.SetOutput(filter) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment