update: 导入日志插件,还需要熟悉
This commit is contained in:
parent
be0484d31e
commit
bd849173d4
|
|
@ -8,6 +8,8 @@ import (
|
||||||
"github.com/cloudwego/hertz/pkg/app"
|
"github.com/cloudwego/hertz/pkg/app"
|
||||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||||
weather_and_earthquake "weather_and_earthquake/biz/model/weather_and_earthquake"
|
weather_and_earthquake "weather_and_earthquake/biz/model/weather_and_earthquake"
|
||||||
|
|
||||||
|
logs "github.com/zxysilent/logs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// QueryMethod .
|
// QueryMethod .
|
||||||
|
|
@ -21,6 +23,7 @@ func QueryMethod(ctx context.Context, c *app.RequestContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logs.Info("QueryMethod req: %v", req)
|
||||||
resp := new(weather_and_earthquake.QueryResp)
|
resp := new(weather_and_earthquake.QueryResp)
|
||||||
resp.Code = req.Op
|
resp.Code = req.Op
|
||||||
c.JSON(consts.StatusOK, resp)
|
c.JSON(consts.StatusOK, resp)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
server:
|
server:
|
||||||
Addr: 0.0.0.0
|
addr: 0.0.0.0
|
||||||
port: 8080
|
port: 8080
|
||||||
|
log_level: 0
|
||||||
|
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
|
|
|
||||||
1
go.mod
1
go.mod
|
|
@ -7,6 +7,7 @@ replace github.com/apache/thrift => github.com/apache/thrift v0.13.0
|
||||||
require (
|
require (
|
||||||
github.com/apache/thrift v0.0.0-00010101000000-000000000000
|
github.com/apache/thrift v0.0.0-00010101000000-000000000000
|
||||||
github.com/cloudwego/hertz v0.10.3
|
github.com/cloudwego/hertz v0.10.3
|
||||||
|
github.com/zxysilent/logs v0.8.4
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -60,6 +60,8 @@ github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhso
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
github.com/zxysilent/logs v0.8.4 h1:z/TFm99ZxSgnrWeKPFxllnPyU7y06mWR0qhrZQ4zJNI=
|
||||||
|
github.com/zxysilent/logs v0.8.4/go.mod h1:cmA0baYm8n2z+8GJwNUvnu7v8GlVNHZNOktZfChaJmI=
|
||||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
|
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
|
||||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import "time"
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Addr string `yaml:"addr"`
|
Addr string `yaml:"addr"`
|
||||||
Port uint32 `yaml:"port"`
|
Port uint32 `yaml:"port"`
|
||||||
|
LogLevel uint16 `yaml:"log_level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Redis struct {
|
type Redis struct {
|
||||||
|
|
|
||||||
19
main.go
19
main.go
|
|
@ -13,6 +13,8 @@ import (
|
||||||
"weather_and_earthquake/internal/config"
|
"weather_and_earthquake/internal/config"
|
||||||
"weather_and_earthquake/internal/data"
|
"weather_and_earthquake/internal/data"
|
||||||
"weather_and_earthquake/internal/middleware"
|
"weather_and_earthquake/internal/middleware"
|
||||||
|
|
||||||
|
logs "github.com/zxysilent/logs"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -61,6 +63,23 @@ func initialize() {
|
||||||
middleware.Apps = apps
|
middleware.Apps = apps
|
||||||
data.DataConf = conf.Data
|
data.DataConf = conf.Data
|
||||||
|
|
||||||
|
log.Println("LogLevel=", conf.Server.LogLevel)
|
||||||
|
logs.SetFile("./logs/logs.log")
|
||||||
|
logs.Warn("Logs warning")
|
||||||
|
logs.Error("Logs error")
|
||||||
|
logs.Info("Logs info")
|
||||||
|
logs.Debug("Logs debug")
|
||||||
|
switch conf.Server.LogLevel {
|
||||||
|
case 1:
|
||||||
|
logs.SetLevel(logs.LINFO)
|
||||||
|
case 2:
|
||||||
|
logs.SetLevel(logs.LWARN)
|
||||||
|
case 3:
|
||||||
|
logs.SetLevel(logs.LERROR)
|
||||||
|
default:
|
||||||
|
logs.SetLevel(logs.LDEBUG)
|
||||||
|
}
|
||||||
|
|
||||||
hostPort := fmt.Sprintf("%s:%d", conf.Server.Addr, conf.Server.Port)
|
hostPort := fmt.Sprintf("%s:%d", conf.Server.Addr, conf.Server.Port)
|
||||||
_server = server.Default(server.WithHostPorts(hostPort))
|
_server = server.Default(server.WithHostPorts(hostPort))
|
||||||
register(_server)
|
register(_server)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue