mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-12-15 20:56:03 +08:00
模块化定时任务,方便在插件中注册任务;增加日志分组
This commit is contained in:
@@ -8,6 +8,7 @@ package queue
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,16 +16,20 @@ const (
|
||||
ProducerLogErrFormat = "生产 [%s] 失败, body:%+v, err:%+v"
|
||||
)
|
||||
|
||||
func Logger() *glog.Logger {
|
||||
return g.Log("queue")
|
||||
}
|
||||
|
||||
// ConsumerLog 消费日志
|
||||
func ConsumerLog(ctx context.Context, topic string, mqMsg MqMsg, err error) {
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, ConsumerLogErrFormat, topic, string(mqMsg.Body), err)
|
||||
Logger().Errorf(ctx, ConsumerLogErrFormat, topic, string(mqMsg.Body), err)
|
||||
}
|
||||
}
|
||||
|
||||
// ProducerLog 生产日志
|
||||
func ProducerLog(ctx context.Context, topic string, mqMsg MqMsg, err error) {
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, ProducerLogErrFormat, topic, string(mqMsg.Body), err)
|
||||
Logger().Errorf(ctx, ProducerLogErrFormat, topic, string(mqMsg.Body), err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user