status-code-override
songzhibin97 3 years ago committed by chenzhihui
parent 8755827c33
commit 996a1d0956
  1. 6
      log/filter.go
  2. 2
      log/helper_writer.go
  3. 14
      log/log.go

@ -66,13 +66,13 @@ func (f *Filter) Log(level Level, keyvals ...interface{}) error {
}
// fkv is used to provide a slice to contains both logger.prefix and keyvals for filter
var fkv []interface{}
if l, ok := f.logger.(*logger); ok {
if len(l.prefix) > 0 {
l, ok := f.logger.(*logger)
if ok && len(l.prefix) > 0 {
fkv = make([]interface{}, 0, len(l.prefix)+len(keyvals))
fkv = append(fkv, l.prefix...)
fkv = append(fkv, keyvals...)
}
} else {
if !ok {
fkv = keyvals
}
if f.filter != nil && f.filter(level, fkv...) {

@ -19,10 +19,8 @@ func WithWriterLevel(level Level) WriterOptionFn {
// WithWriteMessageKey set writerWrapper helper message key.
func WithWriteMessageKey(key string) WriterOptionFn {
return func(w *writerWrapper) {
if key != "" {
w.helper.msgKey = key
}
}
}
// NewWriter return a writer wrapper.

@ -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.

Loading…
Cancel
Save