Skip to content

Can we make BufferPool bind to Logger? #1247

@edoger

Description

@edoger

Sometimes we need to specify different buffer pools for different loggers. The current version makes it impossible for us to do so!

like:

Logger.SetBufferPool(pool BufferPool)

The advantage of this is that loggers for different purposes can use different buffers.

type LimitBufferPool struct {
    pool *sync.Pool
    cap int
}

func (p *LimitBufferPool) Put(buf *bytes.Buffer) {
    if buf.Cap() > p.cap {
        return
    }
    p.pool.Put(buf)
}

func (p *LimitBufferPool) Get() *bytes.Buffer {
    return p.pool.Get().(*bytes.Buffer)
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions