调整日志等级

This commit is contained in:
2025-10-29 19:14:26 +08:00
parent ff45c59946
commit 7ac9e49212
2 changed files with 26 additions and 22 deletions

View File

@@ -12,6 +12,7 @@ import (
// setupRoutes 设置所有 API 路由
// 在此方法中,使用已初始化的控制器实例将其路由注册到 Gin 引擎中。
func (a *API) setupRoutes() {
a.logger.Info("开始初始化所有 API 路由")
// --- Public Routes ---
// 这些路由不需要身份验证
@@ -19,7 +20,7 @@ func (a *API) setupRoutes() {
// 用户注册和登录
a.engine.POST("/api/v1/users", a.userController.CreateUser) // 注册新用户
a.engine.POST("/api/v1/users/login", a.userController.Login) // 用户登录
a.logger.Info("公开接口注册成功:用户注册、登录")
a.logger.Debug("公开接口注册成功:用户注册、登录")
// 注册 pprof 路由
pprofGroup := a.engine.Group("/debug/pprof")
@@ -37,15 +38,15 @@ func (a *API) setupRoutes() {
pprofGroup.GET("/mutex", gin.WrapH(pprof.Handler("mutex"))) // pprof 互斥锁
pprofGroup.GET("/threadcreate", gin.WrapH(pprof.Handler("threadcreate")))
}
a.logger.Info("pprof 接口注册成功")
a.logger.Debug("pprof 接口注册成功")
// 上行事件监听路由
a.engine.POST("/upstream", gin.WrapH(a.listenHandler.Handler())) // 处理设备上行事件
a.logger.Info("上行事件监听接口注册成功")
a.logger.Debug("上行事件监听接口注册成功")
// 添加 Swagger UI 路由, Swagger UI可在 /swagger/index.html 上找到
a.engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // Swagger UI 接口
a.logger.Info("Swagger UI 接口注册成功")
a.logger.Debug("Swagger UI 接口注册成功")
// --- Authenticated Routes ---
// 所有在此注册的路由都需要通过 JWT 身份验证
@@ -59,7 +60,7 @@ func (a *API) setupRoutes() {
userGroup.GET("/:id/history", a.userController.ListUserHistory) // 获取用户操作历史
userGroup.POST("/:id/notifications/test", a.userController.SendTestNotification)
}
a.logger.Info("用户相关接口注册成功 (需要认证和审计)")
a.logger.Debug("用户相关接口注册成功 (需要认证和审计)")
// 设备相关路由组
deviceGroup := authGroup.Group("/devices")
@@ -71,7 +72,7 @@ func (a *API) setupRoutes() {
deviceGroup.DELETE("/:id", a.deviceController.DeleteDevice) // 删除设备
deviceGroup.POST("/manual-control/:id", a.deviceController.ManualControl) // 手动控制设备
}
a.logger.Info("设备相关接口注册成功 (需要认证和审计)")
a.logger.Debug("设备相关接口注册成功 (需要认证和审计)")
// 区域主控相关路由组
areaControllerGroup := authGroup.Group("/area-controllers")
@@ -82,7 +83,7 @@ func (a *API) setupRoutes() {
areaControllerGroup.PUT("/:id", a.deviceController.UpdateAreaController) // 更新区域主控
areaControllerGroup.DELETE("/:id", a.deviceController.DeleteAreaController) // 删除区域主控
}
a.logger.Info("区域主控相关接口注册成功 (需要认证和审计)")
a.logger.Debug("区域主控相关接口注册成功 (需要认证和审计)")
// 设备模板相关路由组
deviceTemplateGroup := authGroup.Group("/device-templates")
@@ -93,7 +94,7 @@ func (a *API) setupRoutes() {
deviceTemplateGroup.PUT("/:id", a.deviceController.UpdateDeviceTemplate) // 更新设备模板
deviceTemplateGroup.DELETE("/:id", a.deviceController.DeleteDeviceTemplate) // 删除设备模板
}
a.logger.Info("设备模板相关接口注册成功 (需要认证和审计)")
a.logger.Debug("设备模板相关接口注册成功 (需要认证和审计)")
// 计划相关路由组
planGroup := authGroup.Group("/plans")
@@ -106,7 +107,7 @@ func (a *API) setupRoutes() {
planGroup.POST("/:id/start", a.planController.StartPlan) // 启动计划
planGroup.POST("/:id/stop", a.planController.StopPlan) // 停止计划
}
a.logger.Info("计划相关接口注册成功 (需要认证和审计)")
a.logger.Debug("计划相关接口注册成功 (需要认证和审计)")
// 猪舍相关路由组
pigHouseGroup := authGroup.Group("/pig-houses")
@@ -117,7 +118,7 @@ func (a *API) setupRoutes() {
pigHouseGroup.PUT("/:id", a.pigFarmController.UpdatePigHouse) // 更新猪舍
pigHouseGroup.DELETE("/:id", a.pigFarmController.DeletePigHouse) // 删除猪舍
}
a.logger.Info("猪舍相关接口注册成功 (需要认证和审计)")
a.logger.Debug("猪舍相关接口注册成功 (需要认证和审计)")
// 猪圈相关路由组
penGroup := authGroup.Group("/pens")
@@ -129,7 +130,7 @@ func (a *API) setupRoutes() {
penGroup.DELETE("/:id", a.pigFarmController.DeletePen) // 删除猪圈
penGroup.PUT("/:id/status", a.pigFarmController.UpdatePenStatus) // 更新猪圈状态
}
a.logger.Info("猪圈相关接口注册成功 (需要认证和审计)")
a.logger.Debug("猪圈相关接口注册成功 (需要认证和审计)")
// 猪群相关路由组
pigBatchGroup := authGroup.Group("/pig-batches")
@@ -154,7 +155,7 @@ func (a *API) setupRoutes() {
pigBatchGroup.POST("/record-death/:id", a.pigBatchController.RecordDeath) // 记录正常猪只死亡事件
pigBatchGroup.POST("/record-cull/:id", a.pigBatchController.RecordCull) // 记录正常猪只淘汰事件
}
a.logger.Info("猪群相关接口注册成功 (需要认证和审计)")
a.logger.Debug("猪群相关接口注册成功 (需要认证和审计)")
// 数据监控相关路由组
monitorGroup := authGroup.Group("/monitor")
@@ -178,6 +179,8 @@ func (a *API) setupRoutes() {
monitorGroup.GET("/pig-sales", a.monitorController.ListPigSales)
monitorGroup.GET("/notifications", a.monitorController.ListNotifications)
}
a.logger.Info("数据监控相关接口注册成功 (需要认证和审计)")
a.logger.Debug("数据监控相关接口注册成功 (需要认证和审计)")
}
a.logger.Debug("所有接口注册成功")
}