From f21f93b7135b18eab2c41a0df9987e05014dee07 Mon Sep 17 00:00:00 2001 From: Ge Song Date: Wed, 12 Apr 2023 17:25:07 +0800 Subject: [PATCH] =?UTF-8?q?log/logjson=E6=8F=90=E4=BE=9BNewSyncWriter?= =?UTF-8?q?=E5=92=8CNewBytesBufferPool;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log/logsdk/logjson/option.go | 4 ++-- log/logsdk/logjson/pool.go | 3 ++- log/logsdk/logjson/writer.go | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/log/logsdk/logjson/option.go b/log/logsdk/logjson/option.go index 8a22402..2929c8d 100644 --- a/log/logsdk/logjson/option.go +++ b/log/logsdk/logjson/option.go @@ -60,10 +60,10 @@ func newConfig(opts ...Option) *config { opt.apply(cfg) } if !cfg.hasPool { - cfg.bytesBufferPool = newBytesBufferPool(512, 4096) + cfg.bytesBufferPool = NewBytesBufferPool(512, 4096) } if cfg.output == nil { - cfg.output = newSyncWriter(os.Stderr) + cfg.output = NewSyncWriter(os.Stderr) } if cfg.timestampFormat == "" { cfg.timestampFormat = time.RFC3339Nano diff --git a/log/logsdk/logjson/pool.go b/log/logsdk/logjson/pool.go index cd99492..7b3bc5b 100644 --- a/log/logsdk/logjson/pool.go +++ b/log/logsdk/logjson/pool.go @@ -10,7 +10,8 @@ type BytesBufferPool interface { Put(buffer *bytes.Buffer) } -func newBytesBufferPool(initialSize, maximumSize int) *bytesBufferPool { +// NewBytesBufferPool 创建并返回 BytesBufferPool +func NewBytesBufferPool(initialSize, maximumSize int) BytesBufferPool { return &bytesBufferPool{ pool: sync.Pool{ New: func() any { diff --git a/log/logsdk/logjson/writer.go b/log/logsdk/logjson/writer.go index fd52d1f..bda4a62 100644 --- a/log/logsdk/logjson/writer.go +++ b/log/logsdk/logjson/writer.go @@ -5,7 +5,8 @@ import ( "sync" ) -func newSyncWriter(writer io.Writer) io.Writer { +// NewSyncWriter 返回写互斥的 io.Writer +func NewSyncWriter(writer io.Writer) io.Writer { return &syncWriter{ writer: writer, lock: sync.Mutex{},