stderr output support
This commit is contained in:
parent
eac80f6d2b
commit
dd89b362c8
19
core.go
19
core.go
@ -80,12 +80,23 @@ func (logger *starlog) build(thread string, isStd bool, isShow bool, handler fun
|
|||||||
}
|
}
|
||||||
if isShow {
|
if isShow {
|
||||||
if !logger.showColor {
|
if !logger.showColor {
|
||||||
fmt.Print(logStr)
|
if level >= logger.errOutputLevel {
|
||||||
|
fmt.Fprint(os.Stderr, logStr)
|
||||||
|
} else {
|
||||||
|
fmt.Print(logStr)
|
||||||
|
}
|
||||||
} else if !logger.onlyColorLevel {
|
} else if !logger.onlyColorLevel {
|
||||||
//logcolor := NewColor(logger.colorList[level]...)
|
if level < logger.errOutputLevel {
|
||||||
logger.colorMe[level].Fprint(stdScreen, logStr)
|
logger.colorMe[level].Fprint(stdScreen, logStr)
|
||||||
|
} else {
|
||||||
|
logger.colorMe[level].Fprint(errScreen, logStr)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprint(stdScreen, logStr)
|
if level < logger.errOutputLevel {
|
||||||
|
fmt.Fprint(stdScreen, logStr)
|
||||||
|
} else {
|
||||||
|
fmt.Fprint(errScreen, logStr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if handler != nil {
|
if handler != nil {
|
||||||
|
15
typed.go
15
typed.go
@ -38,11 +38,13 @@ var (
|
|||||||
stackStopChan chan int
|
stackStopChan chan int
|
||||||
stackMu sync.Mutex
|
stackMu sync.Mutex
|
||||||
stdScreen io.Writer = colorable.NewColorableStdout()
|
stdScreen io.Writer = colorable.NewColorableStdout()
|
||||||
|
errScreen io.Writer = colorable.NewColorableStderr()
|
||||||
)
|
)
|
||||||
|
|
||||||
type starlog struct {
|
type starlog struct {
|
||||||
mu *sync.Mutex
|
mu *sync.Mutex
|
||||||
output io.Writer
|
output io.Writer
|
||||||
|
errOutputLevel int
|
||||||
showFuncName bool
|
showFuncName bool
|
||||||
showThread bool
|
showThread bool
|
||||||
showLevel bool
|
showLevel bool
|
||||||
@ -80,6 +82,7 @@ func newLogCore(out io.Writer) *starlog {
|
|||||||
return &starlog{
|
return &starlog{
|
||||||
mu: &sync.Mutex{},
|
mu: &sync.Mutex{},
|
||||||
output: out,
|
output: out,
|
||||||
|
errOutputLevel: LvError,
|
||||||
showFuncName: true,
|
showFuncName: true,
|
||||||
showThread: true,
|
showThread: true,
|
||||||
showLevel: 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 {
|
func (logger *StarLogger) NewFlag() *StarLogger {
|
||||||
return &StarLogger{
|
return &StarLogger{
|
||||||
thread: getRandomFlag(false),
|
thread: getRandomFlag(false),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user