作者 yangfu

kafka日志

... ... @@ -3,7 +3,9 @@ package main
import (
"fmt"
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/log/logrus"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log"
... ... @@ -11,7 +13,13 @@ import (
)
func main() {
log.Logger.Info("server start!")
log.Logger.Info("server start ....")
log.Logger.Info(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG))
if constant.ENABLE_KAFKA_LOG {
w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOST, constant.TOPIC_LOG_STASH, false)
log.Logger.AddHook(w)
}
log.Logger.Info("server start!")
web.Run()
}
... ...
... ... @@ -12,12 +12,12 @@ var (
)
func init() {
if os.Getenv("KAFKA_HOST") != "" {
POSTGRESQL_HOST = os.Getenv("KAFKA_HOST")
}
if os.Getenv("TOPIC_LOG_STASH") != "" {
POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")
}
//if os.Getenv("KAFKA_HOST") != "" {
// POSTGRESQL_HOST = os.Getenv("KAFKA_HOST")
//}
//if os.Getenv("TOPIC_LOG_STASH") != "" {
// POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")
//}
if os.Getenv("ENABLE_KAFKA_LOG") != "" {
ENABLE_KAFKA_LOG = true
}
... ...
... ... @@ -12,9 +12,4 @@ func init() {
Logger = logrus.NewLogrusLogger()
Logger.SetServiceName(constant.SERVICE_NAME)
Logger.SetLevel(constant.LOG_LEVEL)
if constant.ENABLE_KAFKA_LOG {
w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOST, constant.TOPIC_LOG_STASH, false)
Logger.AddHook(w)
}
}
... ...