作为中国人,始终不太习惯golang中自带的日志输出时间格式。这里将log库作一点修改来适合自己。
其中color.New是CLI的颜色输出库 “github.com/gookit/color”
type logWriter struct {
}
func (writer logWriter) Write(bytes []byte) (int, error) {
return fmt.Printf("%s %s %s", time.Now().UTC().Format("2006-01-02 15:04:05"), color.New(color.FgGreen).Render("[SYS]"), string(bytes))
}
func main() {
log.SetFlags(0)
log.SetOutput(new(logWriter))
}