optimize log tool

This commit is contained in:
hoteas
2021-05-25 19:53:34 +08:00
parent 770f0a94c9
commit 740059075a
6 changed files with 41 additions and 27 deletions
+9 -4
View File
@@ -164,7 +164,8 @@ func (that *Application) Run(router Router) {
func (that *Application) SetConnectDB(connect func(err ...*Error) (master, slave *sql.DB)) {
that.connectDbFunc = connect
that.Db.SetConnect(that.connectDbFunc)
that.Db.SetConnect(that.connectDbFunc, &that.Error)
}
@@ -197,6 +198,7 @@ func (that *Application) SetCache(cache CacheIns) {
func (that *Application) SetConfig(configPath ...string) {
that.Log = GetLog("", true)
that.Error = Error{Logger: that.Log}
if len(configPath) != 0 {
that.configPath = configPath[0]
}
@@ -223,7 +225,7 @@ func (that *Application) SetConfig(configPath ...string) {
}
that.Log = GetLog(that.Config.GetString("logFile"), true)
that.Error = Error{Logger: that.Log}
if that.Config.GetBool("webConnectLogShow") {
that.WebConnectLog = GetLog(that.Config.GetString("webConnectLogFile"), false)
}
@@ -465,6 +467,7 @@ func Init(config string) Application {
appIns := Application{}
//手动模式,
appIns.SetConfig(config)
SetDB(&appIns)
//appIns.SetCache()
return appIns
@@ -483,6 +486,8 @@ func SetDB(appIns *Application) {
}
}
func SetMysqlDB(appIns *Application, config Map) {
appIns.Db.Type = "mysql"
appIns.SetConnectDB(func(err ...*Error) (master, slave *sql.DB) {
//master数据库配置
query := config.GetString("user") + ":" + config.GetString("password") +
@@ -507,9 +512,10 @@ func SetMysqlDB(appIns *Application, config Map) {
return master, slave
//return DB
})
appIns.Db.Type = "mysql"
}
func SetSqliteDB(appIns *Application, config Map) {
appIns.Db.Type = "sqlite"
appIns.SetConnectDB(func(err ...*Error) (master, slave *sql.DB) {
db, e := sql.Open("sqlite3", config.GetString("path"))
if e != nil && len(err) != 0 {
@@ -519,5 +525,4 @@ func SetSqliteDB(appIns *Application, config Map) {
return master, slave
})
appIns.Db.Type = "sqlite"
}