Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we make BufferPool bind to Logger? #1247

Closed
edoger opened this issue Mar 16, 2021 · 4 comments
Closed

Can we make BufferPool bind to Logger? #1247

edoger opened this issue Mar 16, 2021 · 4 comments

Comments

@edoger
Copy link
Contributor

edoger commented Mar 16, 2021

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)
}
@dgsb
Copy link
Collaborator

dgsb commented Apr 17, 2021

That could be practical indeed. The trick though is too make the implementation so that it doesn't break application which does not set this field upon static declaration of a logger.
A pull request would be most welcome.

@edoger
Copy link
Contributor Author

edoger commented Apr 19, 2021

I'll implement it by the end of the weekend.

@edoger
Copy link
Contributor Author

edoger commented Apr 20, 2021

link #1253

@edoger
Copy link
Contributor Author

edoger commented Apr 22, 2021

The feature has been implemented.

@edoger edoger closed this as completed Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants