mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Updates for new logging to appease govet
Govet doesn't like functions that look like format handlers not ending in `f`, such as Debug() vs Debugf(). This is changing some of the new log handling to use 'f' function names to appease govet. Updated the implicit handling of including the client as an arg without being used in a format string. Now the client object simply has a Errorf function for logging errors and it adds itself onto the format string.
This commit is contained in:
@@ -43,7 +43,7 @@ func NewFileLogger(filename string, time, debug, trace bool) *Logger {
|
||||
fileflags := os.O_WRONLY | os.O_APPEND | os.O_CREATE
|
||||
f, err := os.OpenFile(filename, fileflags, 0660)
|
||||
if err != nil {
|
||||
log.Fatal("error opening file: %v", err)
|
||||
log.Fatalf("error opening file: %v", err)
|
||||
}
|
||||
|
||||
flags := 0
|
||||
@@ -78,25 +78,25 @@ func setColoredLabelFormats(l *Logger) {
|
||||
l.traceLabel = fmt.Sprintf(colorFormat, 33, "TRACE")
|
||||
}
|
||||
|
||||
func (l *Logger) Notice(format string, v ...interface{}) {
|
||||
func (l *Logger) Noticef(format string, v ...interface{}) {
|
||||
l.logger.Printf(l.infoLabel+format, v...)
|
||||
}
|
||||
|
||||
func (l *Logger) Error(format string, v ...interface{}) {
|
||||
func (l *Logger) Errorf(format string, v ...interface{}) {
|
||||
l.logger.Printf(l.errorLabel+format, v...)
|
||||
}
|
||||
|
||||
func (l *Logger) Fatal(format string, v ...interface{}) {
|
||||
func (l *Logger) Fatalf(format string, v ...interface{}) {
|
||||
l.logger.Fatalf(l.fatalLabel+format, v)
|
||||
}
|
||||
|
||||
func (l *Logger) Debug(format string, v ...interface{}) {
|
||||
func (l *Logger) Debugf(format string, v ...interface{}) {
|
||||
if l.debug == true {
|
||||
l.logger.Printf(l.debugLabel+format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Logger) Trace(format string, v ...interface{}) {
|
||||
func (l *Logger) Tracef(format string, v ...interface{}) {
|
||||
if l.trace == true {
|
||||
l.logger.Printf(l.traceLabel+format, v...)
|
||||
}
|
||||
|
||||
@@ -46,42 +46,42 @@ func TestStdLoggerWithDebugTraceAndTime(t *testing.T) {
|
||||
func TestStdLoggerNotice(t *testing.T) {
|
||||
expectOutput(t, func() {
|
||||
logger := NewStdLogger(false, false, false, false)
|
||||
logger.Notice("foo")
|
||||
logger.Noticef("foo")
|
||||
}, "[INFO] foo\n")
|
||||
}
|
||||
|
||||
func TestStdLoggerNoticeWithColor(t *testing.T) {
|
||||
expectOutput(t, func() {
|
||||
logger := NewStdLogger(false, false, false, true)
|
||||
logger.Notice("foo")
|
||||
logger.Noticef("foo")
|
||||
}, "[\x1b[32mINFO\x1b[0m] foo\n")
|
||||
}
|
||||
|
||||
func TestStdLoggerDebug(t *testing.T) {
|
||||
expectOutput(t, func() {
|
||||
logger := NewStdLogger(false, true, false, false)
|
||||
logger.Debug("foo %s", "bar")
|
||||
logger.Debugf("foo %s", "bar")
|
||||
}, "[DEBUG] foo bar\n")
|
||||
}
|
||||
|
||||
func TestStdLoggerDebugWithOutDebug(t *testing.T) {
|
||||
expectOutput(t, func() {
|
||||
logger := NewStdLogger(false, false, false, false)
|
||||
logger.Debug("foo")
|
||||
logger.Debugf("foo")
|
||||
}, "")
|
||||
}
|
||||
|
||||
func TestStdLoggerTrace(t *testing.T) {
|
||||
expectOutput(t, func() {
|
||||
logger := NewStdLogger(false, false, true, false)
|
||||
logger.Trace("foo")
|
||||
logger.Tracef("foo")
|
||||
}, "[TRACE] foo\n")
|
||||
}
|
||||
|
||||
func TestStdLoggerTraceWithOutDebug(t *testing.T) {
|
||||
expectOutput(t, func() {
|
||||
logger := NewStdLogger(false, false, false, false)
|
||||
logger.Trace("foo")
|
||||
logger.Tracef("foo")
|
||||
}, "")
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func TestFileLogger(t *testing.T) {
|
||||
file.Close()
|
||||
|
||||
logger := NewFileLogger(file.Name(), false, false, false)
|
||||
logger.Notice("foo")
|
||||
logger.Noticef("foo")
|
||||
|
||||
buf, err := ioutil.ReadFile(file.Name())
|
||||
if err != nil {
|
||||
|
||||
@@ -59,25 +59,25 @@ func getNetworkAndAddr(fqn string) (network, addr string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (l *SysLogger) Notice(format string, v ...interface{}) {
|
||||
func (l *SysLogger) Noticef(format string, v ...interface{}) {
|
||||
l.writer.Notice(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
func (l *SysLogger) Fatal(format string, v ...interface{}) {
|
||||
func (l *SysLogger) Fatalf(format string, v ...interface{}) {
|
||||
l.writer.Crit(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
func (l *SysLogger) Error(format string, v ...interface{}) {
|
||||
func (l *SysLogger) Errorf(format string, v ...interface{}) {
|
||||
l.writer.Err(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
func (l *SysLogger) Debug(format string, v ...interface{}) {
|
||||
func (l *SysLogger) Debugf(format string, v ...interface{}) {
|
||||
if l.debug {
|
||||
l.writer.Debug(fmt.Sprintf(format, v...))
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SysLogger) Trace(format string, v ...interface{}) {
|
||||
func (l *SysLogger) Tracef(format string, v ...interface{}) {
|
||||
if l.trace {
|
||||
l.writer.Notice(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func TestRemoteSysLoggerNotice(t *testing.T) {
|
||||
startServer(done)
|
||||
logger := NewRemoteSysLogger(serverFQN, true, true)
|
||||
|
||||
logger.Notice("foo %s", "bar")
|
||||
logger.Noticef("foo %s", "bar")
|
||||
expectSyslogOutput(t, <-done, "foo bar\n")
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestRemoteSysLoggerDebug(t *testing.T) {
|
||||
startServer(done)
|
||||
logger := NewRemoteSysLogger(serverFQN, true, true)
|
||||
|
||||
logger.Debug("foo %s", "qux")
|
||||
logger.Debugf("foo %s", "qux")
|
||||
expectSyslogOutput(t, <-done, "foo qux\n")
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestRemoteSysLoggerDebugDisabled(t *testing.T) {
|
||||
startServer(done)
|
||||
logger := NewRemoteSysLogger(serverFQN, false, false)
|
||||
|
||||
logger.Debug("foo %s", "qux")
|
||||
logger.Debugf("foo %s", "qux")
|
||||
rcvd := <-done
|
||||
if rcvd != "" {
|
||||
t.Fatalf("Unexpected syslog response %s\n", rcvd)
|
||||
@@ -84,7 +84,7 @@ func TestRemoteSysLoggerTrace(t *testing.T) {
|
||||
startServer(done)
|
||||
logger := NewRemoteSysLogger(serverFQN, true, true)
|
||||
|
||||
logger.Trace("foo %s", "qux")
|
||||
logger.Tracef("foo %s", "qux")
|
||||
expectSyslogOutput(t, <-done, "foo qux\n")
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestRemoteSysLoggerTraceDisabled(t *testing.T) {
|
||||
startServer(done)
|
||||
logger := NewRemoteSysLogger(serverFQN, true, false)
|
||||
|
||||
logger.Trace("foo %s", "qux")
|
||||
logger.Tracef("foo %s", "qux")
|
||||
rcvd := <-done
|
||||
if rcvd != "" {
|
||||
t.Fatalf("Unexpected syslog response %s\n", rcvd)
|
||||
|
||||
Reference in New Issue
Block a user