Allow interface{} keys when using logger
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
@@ -54,8 +54,14 @@ func GetLoggerWithField(ctx Context, key, value interface{}, keys ...interface{}
|
||||
// GetLoggerWithFields returns a logger instance with the specified fields
|
||||
// without affecting the context. Extra specified keys will be resolved from
|
||||
// the context.
|
||||
func GetLoggerWithFields(ctx Context, fields map[string]interface{}, keys ...interface{}) Logger {
|
||||
return getLogrusLogger(ctx, keys...).WithFields(logrus.Fields(fields))
|
||||
func GetLoggerWithFields(ctx Context, fields map[interface{}]interface{}, keys ...interface{}) Logger {
|
||||
// must convert from interface{} -> interface{} to string -> interface{} for logrus.
|
||||
lfields := make(logrus.Fields, len(fields))
|
||||
for key, value := range fields {
|
||||
lfields[fmt.Sprint(key)] = value
|
||||
}
|
||||
|
||||
return getLogrusLogger(ctx, keys...).WithFields(lfields)
|
||||
}
|
||||
|
||||
// GetLogger returns the logger from the current context, if present. If one
|
||||
@@ -89,7 +95,6 @@ func getLogrusLogger(ctx Context, keys ...interface{}) *logrus.Entry {
|
||||
}
|
||||
|
||||
fields := logrus.Fields{}
|
||||
|
||||
for _, key := range keys {
|
||||
v := ctx.Value(key)
|
||||
if v != nil {
|
||||
|
Reference in New Issue
Block a user