Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func PrepareConsoleLoggerLevel(defaultLevel log.Level) func(context.Context, *cl
if globalBool(c, "debug") || globalBool(c, "verbose") {
level = log.TRACE
}
log.SetConsoleLogger(log.DEFAULT, "console-default", level)
log.SetupStderrLogger(log.DEFAULT, "console-stderr", level)
return ctx, nil
}
}
Expand Down
21 changes: 16 additions & 5 deletions modules/log/logger_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,23 @@ func IsLoggerEnabled(name string) bool {
return GetManager().GetLogger(name).IsEnabled()
}

func SetConsoleLogger(loggerName, writerName string, level Level) {
func SetupStderrLogger(loggerName, writerName string, level Level) {
writer := NewEventWriterConsole(writerName, WriterMode{
Level: level,
Flags: FlagsFromBits(LstdFlags),
Colorize: CanColorStdout,
WriterOption: WriterConsoleOption{},
Level: level,
Flags: FlagsFromBits(LstdFlags),
Colorize: CanColorStderr,

// For most CLI commands, it's better to use Stderr as log output:
// this logger is installed early (app.Before), before subcommands like "dump" redirect logging to stderr.
// If Stdout, early log output (e.g.: warning during config loading) goes to stdout
// and corrupts any command that writes data to stdout (e.g. "gitea dump --file -").
//
// It is inconsistent with the web server's default console logger from config
// (which will be initialized later and use Stdout by default), but there is no other way at the moment:
// many existing users depend on such behavior to collect web logs (e.g. fail2ban).
//
// Maybe need to refactor the logger system again in the future.
WriterOption: WriterConsoleOption{Stderr: true},
Comment thread
wxiaoguang marked this conversation as resolved.
})
GetManager().GetLogger(loggerName).ReplaceAllWriters(writer)
}
2 changes: 1 addition & 1 deletion modules/setting/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func initLoggerByName(manager *log.LoggerManager, rootCfg ConfigProvider, logger
}

func InitSQLLoggersForCli(level log.Level) {
log.SetConsoleLogger("xorm", "console", level)
log.SetupStderrLogger("xorm", "console-stderr", level)
}

func IsAccessLogEnabled() bool {
Expand Down
4 changes: 2 additions & 2 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func init() {
AppVer = "dev"
}

// We can rely on log.CanColorStdout being set properly because modules/log/console_windows.go comes before modules/setting/setting.go lexicographically
// FIXME: the logger shouldn't be initialized here, the app entry should initialize the logger
// By default set this logger at Info - we'll change it later, but we need to start with something.
log.SetConsoleLogger(log.DEFAULT, "console", log.INFO)
log.SetupStderrLogger(log.DEFAULT, "console-stderr", log.INFO)
}

// IsRunUserMatchCurrentUser returns false if configured run user does not match
Expand Down
Loading