diff options
author | zeripath <art27@cantab.net> | 2020-07-06 01:07:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-05 20:07:07 -0400 |
commit | c5b08f6d5a73e6ba84da84e804d05a8dd3d651be (patch) | |
tree | 7e0f72b9c62b8764d000614714c91a01ebbee223 /modules/log/log.go | |
parent | 38fb087d1983ca8320fb1a8c90150ae7956b358d (diff) | |
download | gitea-c5b08f6d5a73e6ba84da84e804d05a8dd3d651be.tar.gz gitea-c5b08f6d5a73e6ba84da84e804d05a8dd3d651be.zip |
Pause, Resume, Release&Reopen, Add and Remove Logging from command line (#11777)
* Make LogDescriptions race safe
* Add manager commands for pausing, resuming, adding and removing loggers
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Placate lint
* Ensure that file logger is run!
* Add support for smtp and conn
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add release-and-reopen
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'modules/log/log.go')
-rw-r--r-- | modules/log/log.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/modules/log/log.go b/modules/log/log.go index 71e88491f1..2a35b5752c 100644 --- a/modules/log/log.go +++ b/modules/log/log.go @@ -5,6 +5,7 @@ package log import ( + "fmt" "os" "runtime" "strings" @@ -192,6 +193,42 @@ func IsFatal() bool { return GetLevel() <= FATAL } +// Pause pauses all the loggers +func Pause() { + NamedLoggers.Range(func(key, value interface{}) bool { + logger := value.(*Logger) + logger.Pause() + logger.Flush() + return true + }) +} + +// Resume resumes all the loggers +func Resume() { + NamedLoggers.Range(func(key, value interface{}) bool { + logger := value.(*Logger) + logger.Resume() + return true + }) +} + +// ReleaseReopen releases and reopens logging files +func ReleaseReopen() error { + var accumulatedErr error + NamedLoggers.Range(func(key, value interface{}) bool { + logger := value.(*Logger) + if err := logger.ReleaseReopen(); err != nil { + if accumulatedErr == nil { + accumulatedErr = fmt.Errorf("Error reopening %s: %v", key.(string), err) + } else { + accumulatedErr = fmt.Errorf("Error reopening %s: %v & %v", key.(string), err, accumulatedErr) + } + } + return true + }) + return accumulatedErr +} + // Close closes all the loggers func Close() { l, ok := NamedLoggers.Load(DEFAULT) |