Skip to content

Commit

Permalink
WIP: handle edge with level key as the last and odd keyval
Browse files Browse the repository at this point in the history
  • Loading branch information
mingan committed Feb 13, 2018
1 parent eafeb58 commit a6dc69e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions log/syslog/syslog_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ func PrioritySelectorOption(selector PrioritySelector) Option {
}

func defaultPrioritySelector(keyvals ...interface{}) gosyslog.Priority {
for i := 0; i < len(keyvals); i += 2 {
l := len(keyvals)
for i := 0; i < l; i += 2 {
if keyvals[i] == level.Key() {
if v, ok := keyvals[i+1].(level.Value); ok {
var val interface{}
if i+1 < l {
val = keyvals[i+1]
}
if v, ok := val.(level.Value); ok {
switch v {
case level.DebugValue():
return gosyslog.LOG_DEBUG
Expand Down
2 changes: 2 additions & 0 deletions log/syslog/syslog_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestSyslogLoggerDefaultPrioritySelector(t *testing.T) {
l.Log("msg", "ten", "level", level.WarnValue())

l.Log("level", level.ErrorValue(), "msg")
l.Log("msg", "eleven", "level")

want := []string{
"warning: level=warn msg=one\n",
Expand All @@ -43,6 +44,7 @@ func TestSyslogLoggerDefaultPrioritySelector(t *testing.T) {
"warning: msg=ten level=warn\n",

"err: level=error msg=null\n",
"info: msg=eleven level=null\n",
}
have := w.writes
if !reflect.DeepEqual(want, have) {
Expand Down

0 comments on commit a6dc69e

Please sign in to comment.