log/EntryProcessor.Process新增ctx参数并且把ReadonlyEntry中的Context移除;

develop
Ge Song 2 years ago
parent 0f50bc0e73
commit b0180865fc

@ -186,7 +186,6 @@ func (entry Entry) log(ctx context.Context, level Level, message string) {
return return
} }
readonlyEntry := ReadonlyEntry{ readonlyEntry := ReadonlyEntry{
Context: ctx,
Fields: newEntry.fields, Fields: newEntry.fields,
Message: message, Message: message,
Time: newEntry.time, Time: newEntry.time,
@ -202,13 +201,12 @@ func (entry Entry) log(ctx context.Context, level Level, message string) {
readonlyEntry.Stack = getStack(newEntry.callerSkip, 32) readonlyEntry.Stack = getStack(newEntry.callerSkip, 32)
} }
for _, processor := range newEntry.logger.getLevelProcessors(level) { for _, processor := range newEntry.logger.getLevelProcessors(level) {
processor.Process(readonlyEntry) processor.Process(ctx, readonlyEntry)
} }
} }
// ReadonlyEntry 是日志系统收集到1条日志记录 // ReadonlyEntry 是日志系统收集到1条日志记录
type ReadonlyEntry struct { type ReadonlyEntry struct {
Context context.Context `json:"-"`
Caller Frame Caller Frame
Stack []Frame Stack []Frame
Time time.Time Time time.Time

@ -1,6 +1,7 @@
package logjson package logjson
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
@ -36,7 +37,7 @@ type Processor struct {
} }
// Process 处理日志 // Process 处理日志
func (processor *Processor) Process(entry logsdk.ReadonlyEntry) { func (processor *Processor) Process(_ context.Context, entry logsdk.ReadonlyEntry) {
m := Entry{ m := Entry{
Stack: entry.Stack, Stack: entry.Stack,
Fields: entry.Fields, Fields: entry.Fields,

@ -1,8 +1,10 @@
package logsdk package logsdk
import "context"
// EntryProcessor 处理日志记录 // EntryProcessor 处理日志记录
type EntryProcessor interface { type EntryProcessor interface {
Process(entry ReadonlyEntry) Process(ctx context.Context, entry ReadonlyEntry)
} }
type levelProcessors [LevelCount][]EntryProcessor type levelProcessors [LevelCount][]EntryProcessor

Loading…
Cancel
Save