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