github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/pcsutil/log_colorable_prefix.go (about) 1 package pcsutil 2 3 import ( 4 "fmt" 5 "github.com/fatih/color" 6 "github.com/fzfile/BaiduPCS-Go/pcsutil/pcstime" 7 "log" 8 ) 9 10 var ( 11 // ErrorColor 设置输出错误的颜色 12 ErrorColor = color.New(color.FgRed).SprintFunc() 13 ) 14 15 // 自定义log writer 16 type logWriter struct{} 17 18 func (logWriter) Write(bytes []byte) (int, error) { 19 return fmt.Fprint(color.Output, "["+pcstime.BeijingTimeOption("Refer")+"] "+string(bytes)) 20 } 21 22 // SetLogPrefix 设置日志输出的时间前缀 23 func SetLogPrefix() { 24 log.SetFlags(0) 25 log.SetOutput(new(logWriter)) 26 }