Skip to content

Commit d877bf7

Browse files
authored
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
1 parent 45d1fc0 commit d877bf7

File tree

5 files changed

+7
-1
lines changed

5 files changed

+7
-1
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ PATH = data/gitea.db
210210
SQLITE_TIMEOUT = 500
211211
; For iterate buffer, default is 50
212212
ITERATE_BUFFER_SIZE = 50
213+
; Show the database generated SQL
214+
LOG_SQL = true
213215

214216
[indexer]
215217
ISSUE_INDEXER_PATH = indexers/issues.bleve

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
121121
- `PASSWD`: **\<empty\>**: Database user password. Use \`your password\` for quoting if you use special characters in the password.
122122
- `SSL_MODE`: **disable**: For PostgreSQL only.
123123
- `PATH`: **data/gitea.db**: For SQLite3 only, the database file path.
124+
- `LOG_SQL`: **true**: Log the executed SQL.
124125

125126
## Indexer (`indexer`)
126127

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ menu:
8080
- `PASSWD`: 数据库用户密码。
8181
- `SSL_MODE`: PostgreSQL数据库是否启用SSL模式。
8282
- `PATH`: Tidb 或者 SQLite3 数据文件存放路径。
83+
- `LOG_SQL`: **true**: 显示生成的SQL,默认为真。
8384

8485
## Security (`security`)
8586

models/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func SetEngine() (err error) {
270270
// WARNING: for serv command, MUST remove the output to os.stdout,
271271
// so use log file to instead print to stdout.
272272
x.SetLogger(log.XORMLogger)
273-
x.ShowSQL(true)
273+
x.ShowSQL(setting.LogSQL)
274274
return nil
275275
}
276276

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ var (
159159
UseMSSQL bool
160160
UsePostgreSQL bool
161161
UseTiDB bool
162+
LogSQL bool
162163

163164
// Indexer settings
164165
Indexer struct {
@@ -931,6 +932,7 @@ func NewContext() {
931932
}
932933
}
933934
IterateBufferSize = Cfg.Section("database").Key("ITERATE_BUFFER_SIZE").MustInt(50)
935+
LogSQL = Cfg.Section("database").Key("LOG_SQL").MustBool(true)
934936

935937
sec = Cfg.Section("attachment")
936938
AttachmentPath = sec.Key("PATH").MustString(path.Join(AppDataPath, "attachments"))

0 commit comments

Comments
 (0)