diff --git a/conn.go b/conn.go index 07f88978..d06f59c0 100644 --- a/conn.go +++ b/conn.go @@ -711,7 +711,7 @@ func (c *Conn) log(lvl LogLevel, line string, args ...interface{}) { return } - logger.Output(2, fmt.Sprintf("%-4s %s %s", logPrefix(lvl), + logger.Output(2, fmt.Sprintf("%-4s %s %s", lvl, fmt.Sprintf(logFmt, c.String()), fmt.Sprintf(line, args...))) } diff --git a/consumer.go b/consumer.go index b3b78f15..a19f2ba9 100644 --- a/consumer.go +++ b/consumer.go @@ -1120,6 +1120,6 @@ func (r *Consumer) log(lvl LogLevel, line string, args ...interface{}) { } logger.Output(2, fmt.Sprintf("%-4s %3d [%s/%s] %s", - logPrefix(lvl), r.id, r.topic, r.channel, + lvl, r.id, r.topic, r.channel, fmt.Sprintf(line, args...))) } diff --git a/delegates.go b/delegates.go index 4bef7aa9..6bfd94f0 100644 --- a/delegates.go +++ b/delegates.go @@ -2,42 +2,31 @@ package nsq import "time" -// LogLevel specifies the severity of a given log message -type LogLevel int - type logger interface { Output(calldepth int, s string) error } -// logging constants +// LogLevel specifies the severity of a given log message +type LogLevel int + const ( LogLevelDebug LogLevel = iota LogLevelInfo LogLevelWarning LogLevelError - - LogLevelDebugPrefix = "DBG" - LogLevelInfoPrefix = "INF" - LogLevelWarningPrefix = "WRN" - LogLevelErrorPrefix = "ERR" ) -// LogPrefix Resolution -func logPrefix(lvl LogLevel) string { - var prefix string - +// String returns the string form for a given LogLevel +func (lvl LogLevel) String() string { switch lvl { - case LogLevelDebug: - prefix = LogLevelDebugPrefix case LogLevelInfo: - prefix = LogLevelInfoPrefix + return "INF" case LogLevelWarning: - prefix = LogLevelWarningPrefix + return "WRN" case LogLevelError: - prefix = LogLevelErrorPrefix + return "ERR" } - - return prefix + return "DBG" } // MessageDelegate is an interface of methods that are used as diff --git a/producer.go b/producer.go index 3ed2d54d..0677514f 100644 --- a/producer.go +++ b/producer.go @@ -330,7 +330,7 @@ func (w *Producer) log(lvl LogLevel, line string, args ...interface{}) { return } - logger.Output(2, fmt.Sprintf("%-4s %3d %s", logPrefix(lvl), w.id, fmt.Sprintf(line, args...))) + logger.Output(2, fmt.Sprintf("%-4s %3d %s", lvl, w.id, fmt.Sprintf(line, args...))) } func (w *Producer) onConnResponse(c *Conn, data []byte) { w.responseChan <- data }