Use global logger for xorm logs and add options (#1997)

Please let me know if this goes in the right direction. Needs some tests and docs.
This commit is contained in:
Robert Kaussow
2023-07-15 01:15:13 +02:00
committed by GitHub
parent 669abdf690
commit 443c23c58a
6 changed files with 159 additions and 1 deletions

View File

@@ -29,6 +29,16 @@ var flags = []cli.Flag{
Name: "log-level",
Usage: "set logging level",
},
&cli.BoolFlag{
EnvVars: []string{"WOODPECKER_LOG_XORM"},
Name: "log-xorm",
Usage: "enable xorm logging",
},
&cli.BoolFlag{
EnvVars: []string{"WOODPECKER_LOG_XORM_SQL"},
Name: "log-xorm-sql",
Usage: "enable xorm sql command logging",
},
&cli.BoolFlag{
EnvVars: []string{"WOODPECKER_DEBUG_PRETTY"},
Name: "pretty",

View File

@@ -54,6 +54,10 @@ import (
func setupStore(c *cli.Context) (store.Store, error) {
datasource := c.String("datasource")
driver := c.String("driver")
xorm := store.XORM{
Log: c.Bool("log-xorm"),
ShowSQL: c.Bool("log-xorm-sql"),
}
if driver == "sqlite3" {
if datastore.SupportedDriver("sqlite3") {
@@ -78,6 +82,7 @@ func setupStore(c *cli.Context) (store.Store, error) {
opts := &store.Opts{
Driver: driver,
Config: datasource,
XORM: xorm,
}
log.Trace().Msgf("setup datastore: %#v", *opts)
store, err := datastore.NewEngine(opts)