Skip to content

Commit 35f37a3

Browse files
Add --quiet and --verbose to gitea web to control initial logging (#16260)
One of the repeatedly reported issues has been that gitea produces too much console logging during set up even if the console logger is turned off. Fundamentally this is due to some otherwise very helpful logging that has to occur before logging is set up. This has come to a head with the merging of #16243 where otherwise potentially helpful Trace logging in the git module now appears on the console. This PR proposes three things: 1. Change the initial default logger to Info not Trace. 2. Change the logging for the AppPath things to Info in recompense. 3. Add two new command line options to gitea web: --quiet and --verbose `gitea web -q` or `gitea web --quiet` will only log Fatal level initially. `gitea web -verbose` will log at Trace. Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 5402155 commit 35f37a3

File tree

9 files changed

+46
-27
lines changed

9 files changed

+46
-27
lines changed

cmd/convert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func runConvert(ctx *cli.Context) error {
2727
return err
2828
}
2929

30-
log.Trace("AppPath: %s", setting.AppPath)
31-
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
32-
log.Trace("Custom path: %s", setting.CustomPath)
33-
log.Trace("Log path: %s", setting.LogRootPath)
30+
log.Info("AppPath: %s", setting.AppPath)
31+
log.Info("AppWorkPath: %s", setting.AppWorkPath)
32+
log.Info("Custom path: %s", setting.CustomPath)
33+
log.Info("Log path: %s", setting.LogRootPath)
3434
setting.InitDBConfig()
3535

3636
if !setting.Database.UseMySQL {

cmd/dump_repo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var CmdDumpRepository = cli.Command{
6969
cli.StringFlag{
7070
Name: "units",
7171
Value: "",
72-
Usage: `Which items will be migrated, one or more units should be separated as comma.
72+
Usage: `Which items will be migrated, one or more units should be separated as comma.
7373
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
7474
},
7575
},
@@ -80,10 +80,10 @@ func runDumpRepository(ctx *cli.Context) error {
8080
return err
8181
}
8282

83-
log.Trace("AppPath: %s", setting.AppPath)
84-
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
85-
log.Trace("Custom path: %s", setting.CustomPath)
86-
log.Trace("Log path: %s", setting.LogRootPath)
83+
log.Info("AppPath: %s", setting.AppPath)
84+
log.Info("AppWorkPath: %s", setting.AppWorkPath)
85+
log.Info("Custom path: %s", setting.CustomPath)
86+
log.Info("Log path: %s", setting.LogRootPath)
8787
setting.InitDBConfig()
8888

8989
var (

cmd/migrate.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ func runMigrate(ctx *cli.Context) error {
2828
return err
2929
}
3030

31-
log.Trace("AppPath: %s", setting.AppPath)
32-
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
33-
log.Trace("Custom path: %s", setting.CustomPath)
34-
log.Trace("Log path: %s", setting.LogRootPath)
31+
log.Info("AppPath: %s", setting.AppPath)
32+
log.Info("AppWorkPath: %s", setting.AppWorkPath)
33+
log.Info("Custom path: %s", setting.CustomPath)
34+
log.Info("Log path: %s", setting.LogRootPath)
3535
setting.InitDBConfig()
3636

3737
if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil {

cmd/migrate_storage.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ func runMigrateStorage(ctx *cli.Context) error {
110110
return err
111111
}
112112

113-
log.Trace("AppPath: %s", setting.AppPath)
114-
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
115-
log.Trace("Custom path: %s", setting.CustomPath)
116-
log.Trace("Log path: %s", setting.LogRootPath)
113+
log.Info("AppPath: %s", setting.AppPath)
114+
log.Info("AppWorkPath: %s", setting.AppWorkPath)
115+
log.Info("Custom path: %s", setting.CustomPath)
116+
log.Info("Log path: %s", setting.LogRootPath)
117117
setting.InitDBConfig()
118118

119119
if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil {

cmd/web.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ and it takes care of all the other things for you`,
4747
Value: setting.PIDFile,
4848
Usage: "Custom pid file path",
4949
},
50+
cli.BoolFlag{
51+
Name: "quiet, q",
52+
Usage: "Only display Fatal logging errors until logging is set-up",
53+
},
54+
cli.BoolFlag{
55+
Name: "verbose",
56+
Usage: "Set initial logging to TRACE level until logging is properly set-up",
57+
},
5058
},
5159
}
5260

@@ -71,6 +79,14 @@ func runHTTPRedirector() {
7179
}
7280

7381
func runWeb(ctx *cli.Context) error {
82+
if ctx.Bool("verbose") {
83+
_ = log.DelLogger("console")
84+
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "trace", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
85+
} else if ctx.Bool("quiet") {
86+
_ = log.DelLogger("console")
87+
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "fatal", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
88+
}
89+
7490
managerCtx, cancel := context.WithCancel(context.Background())
7591
graceful.InitManager(managerCtx)
7692
defer cancel()

docs/content/doc/usage/command-line.en-us.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Starts the server:
4646
- `--port number`, `-p number`: Port number. Optional. (default: 3000). Overrides configuration file.
4747
- `--install-port number`: Port number to run the install page on. Optional. (default: 3000). Overrides configuration file.
4848
- `--pid path`, `-P path`: Pidfile path. Optional.
49+
- `--quiet`, `-q`: Only emit Fatal logs on the console for logs emitted before logging set up.
50+
- `--verbose`: Emit tracing logs on the console for logs emitted before logging is set-up.
4951
- Examples:
5052
- `gitea web`
5153
- `gitea web --port 80`

modules/setting/setting.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ func getWorkPath(appPath string) string {
469469
func init() {
470470
IsWindows = runtime.GOOS == "windows"
471471
// We can rely on log.CanColorStdout being set properly because modules/log/console_windows.go comes before modules/setting/setting.go lexicographically
472-
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "trace", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
472+
// By default set this logger at Info - we'll change it later but we need to start with something.
473+
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "info", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
473474

474475
var err error
475476
if AppPath, err = getAppPath(); err != nil {

routers/init.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ func GlobalInit(ctx context.Context) {
7272
log.Info(git.VersionInfo())
7373

7474
git.CheckLFSVersion()
75-
log.Trace("AppPath: %s", setting.AppPath)
76-
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
77-
log.Trace("Custom path: %s", setting.CustomPath)
78-
log.Trace("Log path: %s", setting.LogRootPath)
75+
log.Info("AppPath: %s", setting.AppPath)
76+
log.Info("AppWorkPath: %s", setting.AppWorkPath)
77+
log.Info("Custom path: %s", setting.CustomPath)
78+
log.Info("Log path: %s", setting.LogRootPath)
7979
log.Info("Run Mode: %s", strings.Title(setting.RunMode))
8080

8181
// Setup i18n

routers/install/setting.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import (
1818
func PreloadSettings(ctx context.Context) bool {
1919
setting.NewContext()
2020
if !setting.InstallLock {
21-
log.Trace("AppPath: %s", setting.AppPath)
22-
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
23-
log.Trace("Custom path: %s", setting.CustomPath)
24-
log.Trace("Log path: %s", setting.LogRootPath)
25-
log.Trace("Preparing to run install page")
21+
log.Info("AppPath: %s", setting.AppPath)
22+
log.Info("AppWorkPath: %s", setting.AppWorkPath)
23+
log.Info("Custom path: %s", setting.CustomPath)
24+
log.Info("Log path: %s", setting.LogRootPath)
25+
log.Info("Preparing to run install page")
2626
translation.InitLocales()
2727
if setting.EnableSQLite3 {
2828
log.Info("SQLite3 Supported")

0 commit comments

Comments
 (0)