cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.04k stars 491 forks source link

hertzzap流程优化建议 #1143

Closed stonebirdjx closed 1 month ago

stonebirdjx commented 1 month ago

打印日志时能不能先判断日志级别呢? 设置info级别后, 分析pprof 还有CtxDebugf的性能消耗

github-actions[bot] commented 1 month ago

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 1 days if no further activity occurs.

li-jin-gou commented 1 month ago

cc @rogerogers

li-jin-gou commented 1 month ago

本地复现

package main

import (
    "context"
    "github.com/cloudwego/hertz/pkg/common/hlog"
    hertzzap "github.com/hertz-contrib/logger/zap"
)

func main() {
    logger := hertzzap.NewLogger()
    hlog.SetLogger(logger)
    hlog.SetLevel(hlog.LevelInfo)

    hlog.CtxInfof(context.Background(), "hello %s", "hertz")
    hlog.CtxDebugf(context.Background(), "hello %s", "hertz")
    logger.Sync()
}

output:

{"level":"info","ts":1719048778.078252,"msg":"hello hertz"}

一切正常

rogerogers commented 1 month ago

没理解啥意思,等级判断是通过 level 的 Enabled 方法判断的,如果有必要可以自定义这个方法的逻辑

github-actions[bot] commented 1 month ago

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 1 days if no further activity occurs.

rogerogers commented 1 month ago

理解了,感谢反馈,做了一版修正

stonebirdjx commented 1 month ago

👍,感谢采纳,果然是中国速度

github-actions[bot] commented 1 month ago

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 1 days if no further activity occurs.