|
@@ -20,13 +20,13 @@ import (
|
|
|
"iot_manager_service/util/logger"
|
|
|
"iot_manager_service/util/minio"
|
|
|
"net/url"
|
|
|
- "os"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
func main() {
|
|
|
+ cfg := config.Instance()
|
|
|
// 只在本地开调试模式
|
|
|
- if isDevEnv() {
|
|
|
+ if cfg.Logger.DbShowLog == 1 {
|
|
|
gin.SetMode(gin.DebugMode)
|
|
|
} else {
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
@@ -43,7 +43,7 @@ func main() {
|
|
|
engine := gin.Default()
|
|
|
|
|
|
router.InitRouter(engine)
|
|
|
- if isDevEnv() {
|
|
|
+ if cfg.Logger.DbShowLog == 1 {
|
|
|
println(gin.DebugMode + "当前为开发环境,会产生较多调试日志")
|
|
|
} else {
|
|
|
println(gin.ReleaseMode)
|
|
@@ -55,15 +55,18 @@ func main() {
|
|
|
func initDB() {
|
|
|
cfg := config.Instance()
|
|
|
dsn := cfg.Database.User + ":" + cfg.Database.Password + "@tcp(" + cfg.Database.Host + ":" + cfg.Database.Port + ")/" + cfg.Database.Name + "?charset=utf8&parseTime=True" + "&loc=" + url.QueryEscape(cfg.Database.Timezone)
|
|
|
- logCfg := gormLogger.New(logger.Logger, gormLogger.Config{
|
|
|
- SlowThreshold: 200 * time.Millisecond,
|
|
|
- LogLevel: gormLogger.Info,
|
|
|
- Colorful: true,
|
|
|
- })
|
|
|
// 如果是本地开发环境 则 打印gorm 查询日志到控制台
|
|
|
- if isDevEnv() {
|
|
|
+ logCfg := gormLogger.Interface(nil)
|
|
|
+ if cfg.Logger.DbShowLog == 1 {
|
|
|
logCfg = gormLogger.Default
|
|
|
+ } else {
|
|
|
+ logCfg = gormLogger.New(logger.Logger, gormLogger.Config{
|
|
|
+ SlowThreshold: 200 * time.Millisecond,
|
|
|
+ LogLevel: gormLogger.Error,
|
|
|
+ Colorful: true,
|
|
|
+ })
|
|
|
}
|
|
|
+
|
|
|
//logCfg = gormLogger.Default
|
|
|
|
|
|
db, err := gorm.Open(mysql.New(mysql.Config{
|
|
@@ -92,15 +95,3 @@ func initDB() {
|
|
|
operation.InitDB(db)
|
|
|
|
|
|
}
|
|
|
-
|
|
|
-// isDevEnv 是否开发环境 本地开发需要添加环境变量
|
|
|
-//
|
|
|
-// [windows] CMD下执行 setx "DEV_ENV" "1"
|
|
|
-// [linux] export DEV_ENV="1"
|
|
|
-func isDevEnv() bool {
|
|
|
- //return true
|
|
|
- if os.Getenv("DEV_ENV") == "1" {
|
|
|
- return true
|
|
|
- }
|
|
|
- return false
|
|
|
-}
|