stderr output support

master
兔子 2 years ago
parent eac80f6d2b
commit dd89b362c8

@ -80,12 +80,23 @@ func (logger *starlog) build(thread string, isStd bool, isShow bool, handler fun
}
if isShow {
if !logger.showColor {
fmt.Print(logStr)
if level >= logger.errOutputLevel {
fmt.Fprint(os.Stderr, logStr)
} else {
fmt.Print(logStr)
}
} else if !logger.onlyColorLevel {
//logcolor := NewColor(logger.colorList[level]...)
logger.colorMe[level].Fprint(stdScreen, logStr)
if level < logger.errOutputLevel {
logger.colorMe[level].Fprint(stdScreen, logStr)
} else {
logger.colorMe[level].Fprint(errScreen, logStr)
}
} else {
fmt.Fprint(stdScreen, logStr)
if level < logger.errOutputLevel {
fmt.Fprint(stdScreen, logStr)
} else {
fmt.Fprint(errScreen, logStr)
}
}
}
if handler != nil {

@ -38,11 +38,13 @@ var (
stackStopChan chan int
stackMu sync.Mutex
stdScreen io.Writer = colorable.NewColorableStdout()
errScreen io.Writer = colorable.NewColorableStderr()
)
type starlog struct {
mu *sync.Mutex
output io.Writer
errOutputLevel int
showFuncName bool
showThread bool
showLevel bool
@ -80,6 +82,7 @@ func newLogCore(out io.Writer) *starlog {
return &starlog{
mu: &sync.Mutex{},
output: out,
errOutputLevel: LvError,
showFuncName: true,
showThread: true,
showLevel: true,
@ -121,6 +124,18 @@ func NewStarlog(out io.Writer) *StarLogger {
}
}
func (logger *StarLogger) StdErrLevel() int {
logger.logcore.mu.Lock()
defer logger.logcore.mu.Unlock()
return logger.logcore.errOutputLevel
}
func (logger *StarLogger) SetStdErrLevel(level int) {
logger.logcore.mu.Lock()
defer logger.logcore.mu.Unlock()
logger.logcore.errOutputLevel = level
}
func (logger *StarLogger) NewFlag() *StarLogger {
return &StarLogger{
thread: getRandomFlag(false),

Loading…
Cancel
Save