log/logjson提供NewSyncWriter和NewBytesBufferPool;

develop
Ge Song 2 years ago
parent 1f39ef8c3a
commit f21f93b713

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

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

@ -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{},

Loading…
Cancel
Save