添加example&优化参数截取

This commit is contained in:
Yun
2024-07-09 16:35:14 +08:00
parent 70699e9701
commit 1abd260929
3 changed files with 64 additions and 20 deletions
+29
View File
@@ -0,0 +1,29 @@
package main
import (
"context"
"github.com/gin-gonic/gin"
"github.com/yuninks/loggerx"
"github.com/yuninks/loggerx/middleware"
)
// curl --location '127.0.0.1:8080/ping'
func main() {
ctx := context.Background()
log := loggerx.NewLogger(ctx, loggerx.SetToConsole())
g := gin.Default()
g.Use(middleware.SetGinTraceIdByLogger(log))
g.Use(middleware.SetGinParams(log))
g.GET("/ping", func(ctx *gin.Context) {
log.Infof(ctx, "GET /ping")
ctx.JSON(200, gin.H{"message": "pong"})
})
g.Run(":8080")
}
+3
View File
@@ -2,6 +2,7 @@ package main
import (
"context"
"time"
"github.com/yuninks/loggerx"
)
@@ -11,6 +12,8 @@ func main() {
log := loggerx.NewLogger(ctx,
// loggerx.SetPrintFile(false),
loggerx.SetToConsole(),
// loggerx.SetTimeZone(time.UTC),
loggerx.SetTimeZone(time.FixedZone("CST", 8*3600)),
)
log.Info(ctx, "哈哈哈2")
log.Info(ctx, "哈哈哈2")