From b0180865fc0eb50fd1b04b4c77fea58e1c6627b3 Mon Sep 17 00:00:00 2001 From: Ge Song Date: Fri, 14 Apr 2023 00:10:13 +0800 Subject: [PATCH] =?UTF-8?q?log/EntryProcessor.Process=E6=96=B0=E5=A2=9Ectx?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=B9=B6=E4=B8=94=E6=8A=8AReadonlyEntry?= =?UTF-8?q?=E4=B8=AD=E7=9A=84Context=E7=A7=BB=E9=99=A4;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log/logsdk/entry.go | 4 +--- log/logsdk/logjson/processor.go | 3 ++- log/logsdk/processor.go | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/log/logsdk/entry.go b/log/logsdk/entry.go index 1bfa0ec..11e72bc 100644 --- a/log/logsdk/entry.go +++ b/log/logsdk/entry.go @@ -186,7 +186,6 @@ func (entry Entry) log(ctx context.Context, level Level, message string) { return } readonlyEntry := ReadonlyEntry{ - Context: ctx, Fields: newEntry.fields, Message: message, Time: newEntry.time, @@ -202,13 +201,12 @@ func (entry Entry) log(ctx context.Context, level Level, message string) { readonlyEntry.Stack = getStack(newEntry.callerSkip, 32) } for _, processor := range newEntry.logger.getLevelProcessors(level) { - processor.Process(readonlyEntry) + processor.Process(ctx, readonlyEntry) } } // ReadonlyEntry 是日志系统收集到1条日志记录 type ReadonlyEntry struct { - Context context.Context `json:"-"` Caller Frame Stack []Frame Time time.Time diff --git a/log/logsdk/logjson/processor.go b/log/logsdk/logjson/processor.go index 39ad5e4..5447119 100644 --- a/log/logsdk/logjson/processor.go +++ b/log/logsdk/logjson/processor.go @@ -1,6 +1,7 @@ package logjson import ( + "context" "encoding/json" "fmt" "io" @@ -36,7 +37,7 @@ type Processor struct { } // Process 处理日志 -func (processor *Processor) Process(entry logsdk.ReadonlyEntry) { +func (processor *Processor) Process(_ context.Context, entry logsdk.ReadonlyEntry) { m := Entry{ Stack: entry.Stack, Fields: entry.Fields, diff --git a/log/logsdk/processor.go b/log/logsdk/processor.go index 4b85d85..59242b5 100644 --- a/log/logsdk/processor.go +++ b/log/logsdk/processor.go @@ -1,8 +1,10 @@ package logsdk +import "context" + // EntryProcessor 处理日志记录 type EntryProcessor interface { - Process(entry ReadonlyEntry) + Process(ctx context.Context, entry ReadonlyEntry) } type levelProcessors [LevelCount][]EntryProcessor