fix with logger (#2062)

* fix with logger
pull/2064/head
Tony Chen 3 years ago committed by GitHub
parent b74e330289
commit 97c103a395
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      contrib/log/aliyun/aliyun.go
  2. 4
      contrib/log/zap/zap.go
  3. 2
      log/global.go
  4. 4
      log/log.go
  5. 4
      log/std.go
  6. 17
      log/value.go

@ -73,6 +73,10 @@ func WithAccessSecret(as string) Option {
type Option func(alc *options)
func (a *aliyunLog) Close() error {
return a.producer.Close(5000)
}
func (a *aliyunLog) Log(level klog.Level, keyvals ...interface{}) error {
buf := level.String()
levelTitle := "level"

@ -46,3 +46,7 @@ func (l *Logger) Log(level log.Level, keyvals ...interface{}) error {
func (l *Logger) Sync() error {
return l.log.Sync()
}
func (l *Logger) Close() error {
return l.log.Sync()
}

@ -49,7 +49,7 @@ func Log(level Level, keyvals ...interface{}) {
// Context with context logger.
func Context(ctx context.Context) *Helper {
return NewHelper(WithContext(ctx, global))
return NewHelper(WithContext(ctx, global.Logger))
}
// Debug logs a message at debug level.

@ -43,7 +43,7 @@ func With(l Logger, kv ...interface{}) Logger {
kvs = append(kvs, kv...)
kvs = append(kvs, c.prefix...)
return &logger{
logger: l,
logger: c.logger,
prefix: kvs,
hasValuer: containsValuer(kvs),
ctx: c.ctx,
@ -58,7 +58,7 @@ func WithContext(ctx context.Context, l Logger) Logger {
return &logger{logger: l, ctx: ctx}
}
return &logger{
logger: l,
logger: c.logger,
prefix: c.prefix,
hasValuer: c.hasValuer,
ctx: ctx,

@ -45,3 +45,7 @@ func (l *stdLogger) Log(level Level, keyvals ...interface{}) error {
l.pool.Put(buf)
return nil
}
func (l *stdLogger) Close() error {
return nil
}

@ -10,7 +10,7 @@ import (
var (
// DefaultCaller is a Valuer that returns the file and line.
DefaultCaller = Caller(3)
DefaultCaller = Caller(4)
// DefaultTimestamp is a Valuer that returns the current wallclock time.
DefaultTimestamp = Timestamp(time.RFC3339)
@ -30,20 +30,7 @@ func Value(ctx context.Context, v interface{}) interface{} {
// Caller returns a Valuer that returns a pkg/file:line description of the caller.
func Caller(depth int) Valuer {
return func(context.Context) interface{} {
d := depth
_, file, line, _ := runtime.Caller(d)
if strings.LastIndex(file, "/log/filter.go") > 0 {
d++
_, file, line, _ = runtime.Caller(d)
}
if strings.LastIndex(file, "/log/helper.go") > 0 {
d++
_, file, line, _ = runtime.Caller(d)
}
if strings.LastIndex(file, "/log/global.go") > 0 {
d++
_, file, line, _ = runtime.Caller(d)
}
_, file, line, _ := runtime.Caller(depth)
idx := strings.LastIndexByte(file, '/')
return file[idx+1:] + ":" + strconv.Itoa(line)
}

Loading…
Cancel
Save