Created
October 15, 2017 02:41
-
-
Save jwreagor/bebfa1952a8fad4215616fd7a522f5db to your computer and use it in GitHub Desktop.
This file contains hidden or 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
if opts.LogFile != "" { | |
logFp, err := os.OpenFile(opts.LogFile, os.O_WRONLY | os.O_APPEND | os.O_CREATE, 0600) | |
checkError(fmt.Sprintf("error opening %s", opts.LogFile), err) | |
defer logFp.Close() | |
// ensure panic output goes to log file | |
syscall.Dup2(int(logFp.Fd()), 1) | |
syscall.Dup2(int(logFp.Fd()), 2) | |
// log as JSON | |
log.SetFormatter(&log.JSONFormatter{}) | |
// send output to file | |
log.SetOutput(logFp) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment