feat(log): 在控制台输出日志

This commit is contained in:
suyiiyii 2025-01-22 14:40:15 +08:00
parent ab65ee1991
commit a57e4cac1c
Signed by: suyiiyii
GPG Key ID: 044704CB29B8AD85
3 changed files with 7 additions and 3 deletions

View File

@ -4,16 +4,16 @@ import (
"net"
"time"
consul "github.com/kitex-contrib/registry-consul"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/server"
kitexlogrus "github.com/kitex-contrib/obs-opentelemetry/logging/logrus"
consul "github.com/kitex-contrib/registry-consul"
"github.com/suyiiyii/hertz101/app/auth/conf"
"github.com/suyiiyii/hertz101/app/auth/kitex_gen/auth/authservice"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
"os"
)
func main() {
@ -27,7 +27,6 @@ func main() {
klog.Error(err.Error())
}
}
func kitexInit() (opts []server.Option) {
// address
addr, err := net.ResolveTCPAddr("tcp", conf.GetConf().Kitex.Address)
@ -61,6 +60,7 @@ func kitexInit() (opts []server.Option) {
FlushInterval: time.Minute,
}
klog.SetOutput(asyncWriter)
klog.SetOutput(os.Stdout)
server.RegisterShutdownHook(func() {
asyncWriter.Sync()
})

View File

@ -4,6 +4,7 @@ package main
import (
"context"
"os"
"time"
"github.com/cloudwego/hertz/pkg/app"
@ -59,6 +60,7 @@ func registerMiddleware(h *server.Hertz) {
h.OnShutdown = append(h.OnShutdown, func(ctx context.Context) {
asyncWriter.Sync()
})
hlog.SetOutput(os.Stdout)
// pprof
if conf.GetConf().Hertz.EnablePprof {

View File

@ -6,6 +6,7 @@ import (
"github.com/suyiiyii/hertz101/app/user/biz/dal/query"
"github.com/suyiiyii/hertz101/common/mtl"
"net"
"os"
"time"
"github.com/cloudwego/kitex/pkg/klog"
@ -75,5 +76,6 @@ func kitexInit() (opts []server.Option) {
server.RegisterShutdownHook(func() {
asyncWriter.Sync()
})
klog.SetOutput(os.Stdout)
return
}