Skip to content

Commit

Permalink
[opt] nazalog: windows平台下,日志级别字段不要携带颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
q191201771 committed May 30, 2024
1 parent 4d2aeec commit 5d45d1d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
8 changes: 1 addition & 7 deletions pkg/nazalog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,7 @@ func (l *logger) Out(level Level, calldepth int, s string) {
writeTime(&l.core.buf, now, l.core.option.TimestampWithMsFlag)
}

if l.core.option.LevelFlag {
if l.core.console != nil {
l.core.buf.WriteString(levelToColorString[level])
} else {
l.core.buf.WriteString(levelToString[level])
}
}
l.writeLevelStringIfNeeded(level)

if l.prefixs != nil {
for _, s := range l.prefixs {
Expand Down
22 changes: 22 additions & 0 deletions pkg/nazalog/log__unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024, Chef. All rights reserved.
// https://github.com/q191201771/naza
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef (191201771@qq.com)

//go:build linux || darwin || netbsd || freebsd || openbsd || dragonfly
// +build linux darwin netbsd freebsd openbsd dragonfly

package nazalog

func (l *logger) writeLevelStringIfNeeded(level Level) {
if l.core.option.LevelFlag {
if l.core.console != nil {
l.core.buf.WriteString(levelToColorString[level])
} else {
l.core.buf.WriteString(levelToString[level])
}
}
}
19 changes: 19 additions & 0 deletions pkg/nazalog/log__windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2024, Chef. All rights reserved.
// https://github.com/q191201771/naza
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef (191201771@qq.com)

//go:build windows
// +build windows

package nazalog

func (l *logger) writeLevelStringIfNeeded(level Level) {
if l.core.option.LevelFlag {
// windows系统不用写带颜色的日志级别字段
l.core.buf.WriteString(levelToString[level])
}
}

0 comments on commit 5d45d1d

Please sign in to comment.