Post

golangのlogのフォーマットを設定したい

type logWriter struct { } func (writer logWriter) Write(bytes []byte) (int, error) { return fmt.Print(time.Now().UTC().Format("2006-01-02T15:04:05.999Z") + " [DEBUG] " + string(bytes)) } func main() { log.SetFlags(0) log.SetOutput(new(logWriter)) log.Println("This is something being logged!") }

How to change the date/time format of Go’s log package - Stack Overflow

This post is licensed under CC BY 4.0 by the author.