mosn / pkg

Common packages used by other repos.
Apache License 2.0
26 stars 28 forks source link

support iobuffer pool error write to log #61

Closed nejisama closed 2 years ago

nejisama commented 2 years ago

支持一个可扩展的函数记录错误信息。在MOSN中可以使用log.DefaultLogger等封装来写入日志,不直接引用log是因为log本身依赖buffer,会形成循环依赖。 测试Example

package main

import (
        "mosn.io/pkg/log"
        "mosn.io/pkg/buffer"
)

func main() {

        buffer.SetLogFunc(func(msg string) {
                log.DefaultLogger.Errorf("[iobuffer] %s", msg)
        })  

        buf := buffer.GetIoBuffer(0)
        buf.Write([]byte("1234"))

        buffer.PutIoBuffer(buf)
        buffer.PutIoBuffer(buf)
}

输出结果

2022-03-30 17:37:25,126 [ERROR] [iobuffer] PutIoBuffer duplicate