From d877bf7e15ebd5d9a74e58f3999e3276e76fa15e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 30 Mar 2018 22:49:46 +0800 Subject: [PATCH] Add config option to enable or disable log executed SQL (#3726) * add config option to enable or disable log executed SQL * rename ShowSQL to LogSQL --- custom/conf/app.ini.sample | 2 ++ docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + docs/content/doc/advanced/config-cheat-sheet.zh-cn.md | 1 + models/models.go | 2 +- modules/setting/setting.go | 2 ++ 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 7876f0a7b6..3bd5a9c270 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -210,6 +210,8 @@ PATH = data/gitea.db SQLITE_TIMEOUT = 500 ; For iterate buffer, default is 50 ITERATE_BUFFER_SIZE = 50 +; Show the database generated SQL +LOG_SQL = true [indexer] ISSUE_INDEXER_PATH = indexers/issues.bleve diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 93b4da9d32..0ec48bd28c 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -121,6 +121,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `PASSWD`: **\**: Database user password. Use \`your password\` for quoting if you use special characters in the password. - `SSL_MODE`: **disable**: For PostgreSQL only. - `PATH`: **data/gitea.db**: For SQLite3 only, the database file path. +- `LOG_SQL`: **true**: Log the executed SQL. ## Indexer (`indexer`) diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index 6320d6a437..09862cc3b7 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -80,6 +80,7 @@ menu: - `PASSWD`: 数据库用户密码。 - `SSL_MODE`: PostgreSQL数据库是否启用SSL模式。 - `PATH`: Tidb 或者 SQLite3 数据文件存放路径。 +- `LOG_SQL`: **true**: 显示生成的SQL,默认为真。 ## Security (`security`) diff --git a/models/models.go b/models/models.go index 7738e1a3c2..b2f5e923e7 100644 --- a/models/models.go +++ b/models/models.go @@ -270,7 +270,7 @@ func SetEngine() (err error) { // WARNING: for serv command, MUST remove the output to os.stdout, // so use log file to instead print to stdout. x.SetLogger(log.XORMLogger) - x.ShowSQL(true) + x.ShowSQL(setting.LogSQL) return nil } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 9ef175d20e..9ba3e5a666 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -159,6 +159,7 @@ var ( UseMSSQL bool UsePostgreSQL bool UseTiDB bool + LogSQL bool // Indexer settings Indexer struct { @@ -931,6 +932,7 @@ func NewContext() { } } IterateBufferSize = Cfg.Section("database").Key("ITERATE_BUFFER_SIZE").MustInt(50) + LogSQL = Cfg.Section("database").Key("LOG_SQL").MustBool(true) sec = Cfg.Section("attachment") AttachmentPath = sec.Key("PATH").MustString(path.Join(AppDataPath, "attachments"))