|
|
|
@ -37,7 +37,10 @@ func (c *logger) Log(level Level, keyvals ...interface{}) error { |
|
|
|
|
|
|
|
|
|
// With with logger fields.
|
|
|
|
|
func With(l Logger, kv ...interface{}) Logger { |
|
|
|
|
if c, ok := l.(*logger); ok { |
|
|
|
|
c, ok := l.(*logger) |
|
|
|
|
if !ok { |
|
|
|
|
return &logger{logs: []Logger{l}, prefix: kv, hasValuer: containsValuer(kv)} |
|
|
|
|
} |
|
|
|
|
kvs := make([]interface{}, 0, len(c.prefix)+len(kv)) |
|
|
|
|
kvs = append(kvs, kv...) |
|
|
|
|
kvs = append(kvs, c.prefix...) |
|
|
|
@ -47,22 +50,21 @@ func With(l Logger, kv ...interface{}) Logger { |
|
|
|
|
hasValuer: containsValuer(kvs), |
|
|
|
|
ctx: c.ctx, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return &logger{logs: []Logger{l}, prefix: kv, hasValuer: containsValuer(kv)} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// WithContext returns a shallow copy of l with its context changed
|
|
|
|
|
// to ctx. The provided ctx must be non-nil.
|
|
|
|
|
func WithContext(ctx context.Context, l Logger) Logger { |
|
|
|
|
if c, ok := l.(*logger); ok { |
|
|
|
|
c, ok := l.(*logger) |
|
|
|
|
if !ok { |
|
|
|
|
return &logger{logs: []Logger{l}, ctx: ctx} |
|
|
|
|
} |
|
|
|
|
return &logger{ |
|
|
|
|
logs: c.logs, |
|
|
|
|
prefix: c.prefix, |
|
|
|
|
hasValuer: c.hasValuer, |
|
|
|
|
ctx: ctx, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return &logger{logs: []Logger{l}, ctx: ctx} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// MultiLogger wraps multi logger.
|
|
|
|
|