Skip to content

Commit

Permalink
support iobuffer pool error write to log (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
nejisama authored Mar 31, 2022
1 parent 63d0c7b commit 949046a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion buffer/iobuffer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
35 changes: 35 additions & 0 deletions buffer/log.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 949046a

Please sign in to comment.