podman
1package logrus
2
3import (
4"bytes"
5"sync"
6)
7
8var (
9bufferPool BufferPool
10)
11
12type BufferPool interface {
13Put(*bytes.Buffer)
14Get() *bytes.Buffer
15}
16
17type defaultPool struct {
18pool *sync.Pool
19}
20
21func (p *defaultPool) Put(buf *bytes.Buffer) {
22p.pool.Put(buf)
23}
24
25func (p *defaultPool) Get() *bytes.Buffer {
26return p.pool.Get().(*bytes.Buffer)
27}
28
29func getBuffer() *bytes.Buffer {
30return bufferPool.Get()
31}
32
33func putBuffer(buf *bytes.Buffer) {
34buf.Reset()
35bufferPool.Put(buf)
36}
37
38// SetBufferPool allows to replace the default logrus buffer pool
39// to better meets the specific needs of an application.
40func SetBufferPool(bp BufferPool) {
41bufferPool = bp
42}
43
44func init() {
45SetBufferPool(&defaultPool{
46pool: &sync.Pool{
47New: func() interface{} {
48return new(bytes.Buffer)
49},
50},
51})
52}
53