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 <art27@cantab.net>

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
zeripath 2021-06-27 01:56:58 +01:00 committed by GitHub
parent 540215588a
commit 35f37a3625
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 27 deletions

View file

@ -27,10 +27,10 @@ func runConvert(ctx *cli.Context) error {
return err return err
} }
log.Trace("AppPath: %s", setting.AppPath) log.Info("AppPath: %s", setting.AppPath)
log.Trace("AppWorkPath: %s", setting.AppWorkPath) log.Info("AppWorkPath: %s", setting.AppWorkPath)
log.Trace("Custom path: %s", setting.CustomPath) log.Info("Custom path: %s", setting.CustomPath)
log.Trace("Log path: %s", setting.LogRootPath) log.Info("Log path: %s", setting.LogRootPath)
setting.InitDBConfig() setting.InitDBConfig()
if !setting.Database.UseMySQL { if !setting.Database.UseMySQL {

View file

@ -80,10 +80,10 @@ func runDumpRepository(ctx *cli.Context) error {
return err return err
} }
log.Trace("AppPath: %s", setting.AppPath) log.Info("AppPath: %s", setting.AppPath)
log.Trace("AppWorkPath: %s", setting.AppWorkPath) log.Info("AppWorkPath: %s", setting.AppWorkPath)
log.Trace("Custom path: %s", setting.CustomPath) log.Info("Custom path: %s", setting.CustomPath)
log.Trace("Log path: %s", setting.LogRootPath) log.Info("Log path: %s", setting.LogRootPath)
setting.InitDBConfig() setting.InitDBConfig()
var ( var (

View file

@ -28,10 +28,10 @@ func runMigrate(ctx *cli.Context) error {
return err return err
} }
log.Trace("AppPath: %s", setting.AppPath) log.Info("AppPath: %s", setting.AppPath)
log.Trace("AppWorkPath: %s", setting.AppWorkPath) log.Info("AppWorkPath: %s", setting.AppWorkPath)
log.Trace("Custom path: %s", setting.CustomPath) log.Info("Custom path: %s", setting.CustomPath)
log.Trace("Log path: %s", setting.LogRootPath) log.Info("Log path: %s", setting.LogRootPath)
setting.InitDBConfig() setting.InitDBConfig()
if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil { if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil {

View file

@ -110,10 +110,10 @@ func runMigrateStorage(ctx *cli.Context) error {
return err return err
} }
log.Trace("AppPath: %s", setting.AppPath) log.Info("AppPath: %s", setting.AppPath)
log.Trace("AppWorkPath: %s", setting.AppWorkPath) log.Info("AppWorkPath: %s", setting.AppWorkPath)
log.Trace("Custom path: %s", setting.CustomPath) log.Info("Custom path: %s", setting.CustomPath)
log.Trace("Log path: %s", setting.LogRootPath) log.Info("Log path: %s", setting.LogRootPath)
setting.InitDBConfig() setting.InitDBConfig()
if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil { if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil {

View file

@ -47,6 +47,14 @@ and it takes care of all the other things for you`,
Value: setting.PIDFile, Value: setting.PIDFile,
Usage: "Custom pid file path", Usage: "Custom pid file path",
}, },
cli.BoolFlag{
Name: "quiet, q",
Usage: "Only display Fatal logging errors until logging is set-up",
},
cli.BoolFlag{
Name: "verbose",
Usage: "Set initial logging to TRACE level until logging is properly set-up",
},
}, },
} }
@ -71,6 +79,14 @@ func runHTTPRedirector() {
} }
func runWeb(ctx *cli.Context) error { func runWeb(ctx *cli.Context) error {
if ctx.Bool("verbose") {
_ = log.DelLogger("console")
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "trace", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
} else if ctx.Bool("quiet") {
_ = log.DelLogger("console")
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "fatal", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
}
managerCtx, cancel := context.WithCancel(context.Background()) managerCtx, cancel := context.WithCancel(context.Background())
graceful.InitManager(managerCtx) graceful.InitManager(managerCtx)
defer cancel() defer cancel()

View file

@ -46,6 +46,8 @@ Starts the server:
- `--port number`, `-p number`: Port number. Optional. (default: 3000). Overrides configuration file. - `--port number`, `-p number`: Port number. Optional. (default: 3000). Overrides configuration file.
- `--install-port number`: Port number to run the install page on. Optional. (default: 3000). Overrides configuration file. - `--install-port number`: Port number to run the install page on. Optional. (default: 3000). Overrides configuration file.
- `--pid path`, `-P path`: Pidfile path. Optional. - `--pid path`, `-P path`: Pidfile path. Optional.
- `--quiet`, `-q`: Only emit Fatal logs on the console for logs emitted before logging set up.
- `--verbose`: Emit tracing logs on the console for logs emitted before logging is set-up.
- Examples: - Examples:
- `gitea web` - `gitea web`
- `gitea web --port 80` - `gitea web --port 80`

View file

@ -469,7 +469,8 @@ func getWorkPath(appPath string) string {
func init() { func init() {
IsWindows = runtime.GOOS == "windows" IsWindows = runtime.GOOS == "windows"
// We can rely on log.CanColorStdout being set properly because modules/log/console_windows.go comes before modules/setting/setting.go lexicographically // We can rely on log.CanColorStdout being set properly because modules/log/console_windows.go comes before modules/setting/setting.go lexicographically
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "trace", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout)) // By default set this logger at Info - we'll change it later but we need to start with something.
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "info", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
var err error var err error
if AppPath, err = getAppPath(); err != nil { if AppPath, err = getAppPath(); err != nil {

View file

@ -72,10 +72,10 @@ func GlobalInit(ctx context.Context) {
log.Info(git.VersionInfo()) log.Info(git.VersionInfo())
git.CheckLFSVersion() git.CheckLFSVersion()
log.Trace("AppPath: %s", setting.AppPath) log.Info("AppPath: %s", setting.AppPath)
log.Trace("AppWorkPath: %s", setting.AppWorkPath) log.Info("AppWorkPath: %s", setting.AppWorkPath)
log.Trace("Custom path: %s", setting.CustomPath) log.Info("Custom path: %s", setting.CustomPath)
log.Trace("Log path: %s", setting.LogRootPath) log.Info("Log path: %s", setting.LogRootPath)
log.Info("Run Mode: %s", strings.Title(setting.RunMode)) log.Info("Run Mode: %s", strings.Title(setting.RunMode))
// Setup i18n // Setup i18n

View file

@ -18,11 +18,11 @@ import (
func PreloadSettings(ctx context.Context) bool { func PreloadSettings(ctx context.Context) bool {
setting.NewContext() setting.NewContext()
if !setting.InstallLock { if !setting.InstallLock {
log.Trace("AppPath: %s", setting.AppPath) log.Info("AppPath: %s", setting.AppPath)
log.Trace("AppWorkPath: %s", setting.AppWorkPath) log.Info("AppWorkPath: %s", setting.AppWorkPath)
log.Trace("Custom path: %s", setting.CustomPath) log.Info("Custom path: %s", setting.CustomPath)
log.Trace("Log path: %s", setting.LogRootPath) log.Info("Log path: %s", setting.LogRootPath)
log.Trace("Preparing to run install page") log.Info("Preparing to run install page")
translation.InitLocales() translation.InitLocales()
if setting.EnableSQLite3 { if setting.EnableSQLite3 {
log.Info("SQLite3 Supported") log.Info("SQLite3 Supported")