mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Add Warnf to logger interface
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This commit is contained in:
@@ -26,6 +26,7 @@ type Logger struct {
|
||||
debug bool
|
||||
trace bool
|
||||
infoLabel string
|
||||
warnLabel string
|
||||
errorLabel string
|
||||
fatalLabel string
|
||||
debugLabel string
|
||||
@@ -108,18 +109,20 @@ func pidPrefix() string {
|
||||
func setPlainLabelFormats(l *Logger) {
|
||||
l.infoLabel = "[INF] "
|
||||
l.debugLabel = "[DBG] "
|
||||
l.warnLabel = "[WRN] "
|
||||
l.errorLabel = "[ERR] "
|
||||
l.fatalLabel = "[FTL] "
|
||||
l.traceLabel = "[TRC] "
|
||||
}
|
||||
|
||||
func setColoredLabelFormats(l *Logger) {
|
||||
colorFormat := "[\x1b[%dm%s\x1b[0m] "
|
||||
l.infoLabel = fmt.Sprintf(colorFormat, 32, "INF")
|
||||
l.debugLabel = fmt.Sprintf(colorFormat, 36, "DBG")
|
||||
l.errorLabel = fmt.Sprintf(colorFormat, 31, "ERR")
|
||||
l.fatalLabel = fmt.Sprintf(colorFormat, 31, "FTL")
|
||||
l.traceLabel = fmt.Sprintf(colorFormat, 33, "TRC")
|
||||
colorFormat := "[\x1b[%sm%s\x1b[0m] "
|
||||
l.infoLabel = fmt.Sprintf(colorFormat, "32", "INF")
|
||||
l.debugLabel = fmt.Sprintf(colorFormat, "36", "DBG")
|
||||
l.warnLabel = fmt.Sprintf(colorFormat, "0;93", "WRN")
|
||||
l.errorLabel = fmt.Sprintf(colorFormat, "31", "ERR")
|
||||
l.fatalLabel = fmt.Sprintf(colorFormat, "31", "FTL")
|
||||
l.traceLabel = fmt.Sprintf(colorFormat, "33", "TRC")
|
||||
}
|
||||
|
||||
// Noticef logs a notice statement
|
||||
@@ -127,6 +130,11 @@ func (l *Logger) Noticef(format string, v ...interface{}) {
|
||||
l.logger.Printf(l.infoLabel+format, v...)
|
||||
}
|
||||
|
||||
// Warnf logs a notice statement
|
||||
func (l *Logger) Warnf(format string, v ...interface{}) {
|
||||
l.logger.Printf(l.warnLabel+format, v...)
|
||||
}
|
||||
|
||||
// Errorf logs an error statement
|
||||
func (l *Logger) Errorf(format string, v ...interface{}) {
|
||||
l.logger.Printf(l.errorLabel+format, v...)
|
||||
|
||||
@@ -102,6 +102,11 @@ func (l *SysLogger) Noticef(format string, v ...interface{}) {
|
||||
l.writer.Notice(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
// Warnf logs a notice statement
|
||||
func (l *SysLogger) Warnf(format string, v ...interface{}) {
|
||||
l.writer.Notice(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
// Fatalf logs a fatal error
|
||||
func (l *SysLogger) Fatalf(format string, v ...interface{}) {
|
||||
l.writer.Crit(fmt.Sprintf(format, v...))
|
||||
|
||||
@@ -80,6 +80,11 @@ func (l *SysLogger) Noticef(format string, v ...interface{}) {
|
||||
l.writer.Info(1, formatMsg("NOTICE", format, v...))
|
||||
}
|
||||
|
||||
// Noticef logs a notice statement
|
||||
func (l *SysLogger) Warnf(format string, v ...interface{}) {
|
||||
l.writer.Info(1, formatMsg("WARN", format, v...))
|
||||
}
|
||||
|
||||
// Fatalf logs a fatal error
|
||||
func (l *SysLogger) Fatalf(format string, v ...interface{}) {
|
||||
msg := formatMsg("FATAL", format, v...)
|
||||
|
||||
@@ -27,6 +27,9 @@ type Logger interface {
|
||||
// Log a notice statement
|
||||
Noticef(format string, v ...interface{})
|
||||
|
||||
// Log a warning statement
|
||||
Warnf(format string, v ...interface{})
|
||||
|
||||
// Log a fatal error
|
||||
Fatalf(format string, v ...interface{})
|
||||
|
||||
@@ -144,6 +147,13 @@ func (s *Server) Errorf(format string, v ...interface{}) {
|
||||
}, format, v...)
|
||||
}
|
||||
|
||||
// Warnf logs a warning error
|
||||
func (s *Server) Warnf(format string, v ...interface{}) {
|
||||
s.executeLogCall(func(logger Logger, format string, v ...interface{}) {
|
||||
logger.Warnf(format, v...)
|
||||
}, format, v...)
|
||||
}
|
||||
|
||||
// Fatalf logs a fatal error
|
||||
func (s *Server) Fatalf(format string, v ...interface{}) {
|
||||
s.executeLogCall(func(logger Logger, format string, v ...interface{}) {
|
||||
|
||||
@@ -58,6 +58,9 @@ func TestSetLogger(t *testing.T) {
|
||||
expectedStr = "This is a Trace"
|
||||
server.Tracef(expectedStr)
|
||||
dl.checkContent(t, expectedStr)
|
||||
expectedStr = "This is a Warning"
|
||||
server.Tracef(expectedStr)
|
||||
dl.checkContent(t, expectedStr)
|
||||
|
||||
// Make sure that we can reset to fal
|
||||
server.SetLogger(dl, false, false)
|
||||
@@ -98,6 +101,11 @@ func (l *DummyLogger) Errorf(format string, v ...interface{}) {
|
||||
defer l.Unlock()
|
||||
l.msg = fmt.Sprintf(format, v...)
|
||||
}
|
||||
func (l *DummyLogger) Warnf(format string, v ...interface{}) {
|
||||
l.Lock()
|
||||
defer l.Unlock()
|
||||
l.msg = fmt.Sprintf(format, v...)
|
||||
}
|
||||
func (l *DummyLogger) Fatalf(format string, v ...interface{}) {
|
||||
l.Lock()
|
||||
defer l.Unlock()
|
||||
|
||||
@@ -677,6 +677,7 @@ type checkDuplicateRouteLogger struct {
|
||||
|
||||
func (l *checkDuplicateRouteLogger) Noticef(format string, v ...interface{}) {}
|
||||
func (l *checkDuplicateRouteLogger) Errorf(format string, v ...interface{}) {}
|
||||
func (l *checkDuplicateRouteLogger) Warnf(format string, v ...interface{}) {}
|
||||
func (l *checkDuplicateRouteLogger) Fatalf(format string, v ...interface{}) {}
|
||||
func (l *checkDuplicateRouteLogger) Tracef(format string, v ...interface{}) {}
|
||||
func (l *checkDuplicateRouteLogger) Debugf(format string, v ...interface{}) {
|
||||
|
||||
@@ -60,6 +60,9 @@ func (d *dummyLogger) Tracef(format string, args ...interface{}) {
|
||||
func (d *dummyLogger) Noticef(format string, args ...interface{}) {
|
||||
}
|
||||
|
||||
func (d *dummyLogger) Warnf(format string, args ...interface{}) {
|
||||
}
|
||||
|
||||
func TestStackFatal(t *testing.T) {
|
||||
d := &dummyLogger{}
|
||||
stackFatalf(d, "test stack %d", 1)
|
||||
|
||||
Reference in New Issue
Block a user