diff --git a/os/glog/glog_logger.go b/os/glog/glog_logger.go index 88475c0e0..5fdc14fed 100644 --- a/os/glog/glog_logger.go +++ b/os/glog/glog_logger.go @@ -43,7 +43,7 @@ const ( defaultFilePerm = os.FileMode(0666) defaultFileExpire = time.Minute pathFilterKey = "/os/glog/glog" - bufferStdOut = "stdOut" + mustWithColor = true ) const ( @@ -228,7 +228,7 @@ func (l *Logger) printToWriter(ctx context.Context, input *HandlerInput) { } // Allow output to stdout? if l.config.StdoutPrint { - if _, err := os.Stdout.Write(input.Buffer(bufferStdOut).Bytes()); err != nil { + if _, err := os.Stdout.Write(input.Buffer(mustWithColor).Bytes()); err != nil { intlog.Error(err) } } diff --git a/os/glog/glog_logger_config.go b/os/glog/glog_logger_config.go index 00c974705..ec970897c 100644 --- a/os/glog/glog_logger_config.go +++ b/os/glog/glog_logger_config.go @@ -42,6 +42,7 @@ type Config struct { RotateBackupExpire time.Duration `json:"rotateBackupExpire"` // Max expire for rotated files, which is 0 in default, means no expiration. RotateBackupCompress int `json:"rotateBackupCompress"` // Compress level for rotated files using gzip algorithm. It's 0 in default, means no compression. RotateCheckInterval time.Duration `json:"rotateCheckInterval"` // Asynchronizely checks the backups and expiration at intervals. It's 1 hour in default. + FileColor bool `json:"fileColor"` // Logging level prefix with color or not (false in default). color logColor `json:"-"` } diff --git a/os/glog/glog_logger_handler.go b/os/glog/glog_logger_handler.go index 37c318643..bfb15d94b 100644 --- a/os/glog/glog_logger_handler.go +++ b/os/glog/glog_logger_handler.go @@ -43,11 +43,11 @@ func (i *HandlerInput) addStringToBuffer(buffer *bytes.Buffer, s string) { buffer.WriteString(s) } -func (i *HandlerInput) Buffer(bufferType ...string) *bytes.Buffer { +func (i *HandlerInput) Buffer(withColor ...bool) *bytes.Buffer { buffer := bytes.NewBuffer(nil) buffer.WriteString(i.TimeFormat) if i.LevelFormat != "" { - if len(bufferType) > 0 && bufferType[0] == bufferStdOut { + if i.logger.config.FileColor || (len(withColor) > 0 && withColor[0] == mustWithColor) { i.addStringToBuffer(buffer, i.getLevelFormatWithColor()) } else { i.addStringToBuffer(buffer, i.LevelFormat)