Skip to content

Commit

Permalink
not support to shrink logger buffer pool size
Browse files Browse the repository at this point in the history
  • Loading branch information
wongoo committed Oct 1, 2019
1 parent eae5084 commit c933d4d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
23 changes: 13 additions & 10 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,21 @@ var (
)

// SetPoolSize set pool size
func SetPoolSize(size int) {
switch {
case int32(size) == poolSize:
func SetPoolSize(s int) {
size := int32(s)

if size == poolSize {
return
case int32(size) > poolSize:
poolBuffers = make([][]byte, size)
poolFlag = make([]int32, size)
poolSize = int32(cap(poolBuffers))
case int32(size) < poolSize:
poolSize = int32(size)
// shrink pool not change the buffer size
}

if size < poolSize {
fmt.Println("not support to shrink logger buffer pool size")
return
}

poolBuffers = make([][]byte, size)
poolFlag = make([]int32, size)
poolSize = int32(cap(poolBuffers))
}

// WriteLog write log data
Expand Down
5 changes: 5 additions & 0 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func TestSetWriter(t *testing.T) {
}
}

func TestSetPoolSize(t *testing.T) {
SetPoolSize(512)
SetPoolSize(128)
}

func TestTimeFormat(t *testing.T) {
now := time.Now()
fmt.Println(now.Format("20060102 15:04:05.999"))
Expand Down
3 changes: 2 additions & 1 deletion loggerprof/loggerprof.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"github.com/vogo/logger"
"io/ioutil"
"log"
"net/http"
_ "net/http/pprof"

"github.com/vogo/logger"
)

func main() {
Expand Down

0 comments on commit c933d4d

Please sign in to comment.