diff --git a/buffer/iobuffer_pool.go b/buffer/iobuffer_pool.go index 0bb136c..f51ea47 100644 --- a/buffer/iobuffer_pool.go +++ b/buffer/iobuffer_pool.go @@ -81,5 +81,9 @@ func NewIoBuffer(size int) IoBuffer { // PutIoBuffer is a a wrapper for ibPool func PutIoBuffer(buf IoBuffer) error { - return ibPool.PutIoBuffer(buf) + err := ibPool.PutIoBuffer(buf) + if err != nil { + logFunc(err.Error()) + } + return err } diff --git a/buffer/log.go b/buffer/log.go new file mode 100644 index 0000000..b05136b --- /dev/null +++ b/buffer/log.go @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package buffer + +import ( + "fmt" + "os" +) + +// logFunc record buffer's error log, default to std error. +// User can be overwrite it with any log implementation function +// For example, use mosn.io/pkg/log logger.Errorf overwrite it. +var logFunc = func(msg string) { + fmt.Fprintf(os.Stderr, "%s", msg) +} + +// SetLogFunc use f overwrite logFunc. +func SetLogFunc(f func(msg string)) { + logFunc = f +}