Skip to content

Commit

Permalink
Merge pull request #122 from mreiferson/log_level_cleanup_122
Browse files Browse the repository at this point in the history
simplify log level string handling
  • Loading branch information
jehiah committed Feb 21, 2015
2 parents 75d97a3 + cf38478 commit be7c240
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
2 changes: 1 addition & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)))
}
2 changes: 1 addition & 1 deletion consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)))
}
29 changes: 9 additions & 20 deletions delegates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit be7c240

Please sign in to comment.