helper.go 352 字节
Newer Older
O
ob-robot 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
package log

import (
	"fmt"

	"github.com/sirupsen/logrus"
)

func Fields(kv ...interface{}) *logrus.Entry {
	length := (len(kv) - 1)
	if length%2 == 1 {
		length -= 1
	}
	fields := logrus.Fields(make(map[string]interface{}, length))
	for i := 0; i < length<<1; i++ {
		fields[fmt.Sprint(kv[i>>1])] = kv[i>>1+1]
	}
	return logrus.WithFields(fields)
}