aboutsummaryrefslogtreecommitdiffstats
path: root/modules/log/event.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/log/event.go')
-rw-r--r--modules/log/event.go64
1 files changed, 63 insertions, 1 deletions
diff --git a/modules/log/event.go b/modules/log/event.go
index 37efa3c230..6975bf749d 100644
--- a/modules/log/event.go
+++ b/modules/log/event.go
@@ -29,6 +29,7 @@ type EventLogger interface {
GetLevel() Level
GetStacktraceLevel() Level
GetName() string
+ ReleaseReopen() error
}
// ChannelledLog represents a cached channel to a LoggerProvider
@@ -117,6 +118,11 @@ func (l *ChannelledLog) Flush() {
l.flush <- true
}
+// ReleaseReopen this ChannelledLog
+func (l *ChannelledLog) ReleaseReopen() error {
+ return l.loggerProvider.ReleaseReopen()
+}
+
// GetLevel gets the level of this ChannelledLog
func (l *ChannelledLog) GetLevel() Level {
return l.loggerProvider.GetLevel()
@@ -145,6 +151,7 @@ type MultiChannelledLog struct {
level Level
stacktraceLevel Level
closed chan bool
+ paused chan bool
}
// NewMultiChannelledLog a new logger instance with given logger provider and config.
@@ -159,6 +166,7 @@ func NewMultiChannelledLog(name string, bufferLength int64) *MultiChannelledLog
stacktraceLevel: NONE,
close: make(chan bool),
closed: make(chan bool),
+ paused: make(chan bool),
}
return m
}
@@ -229,6 +237,33 @@ func (m *MultiChannelledLog) closeLoggers() {
m.closed <- true
}
+// Pause pauses this Logger
+func (m *MultiChannelledLog) Pause() {
+ m.paused <- true
+}
+
+// Resume resumes this Logger
+func (m *MultiChannelledLog) Resume() {
+ m.paused <- false
+}
+
+// ReleaseReopen causes this logger to tell its subloggers to release and reopen
+func (m *MultiChannelledLog) ReleaseReopen() error {
+ m.mutex.Lock()
+ defer m.mutex.Unlock()
+ var accumulatedErr error
+ for _, logger := range m.loggers {
+ if err := logger.ReleaseReopen(); err != nil {
+ if accumulatedErr == nil {
+ accumulatedErr = fmt.Errorf("Error whilst reopening: %s Error: %v", logger.GetName(), err)
+ } else {
+ accumulatedErr = fmt.Errorf("Error whilst reopening: %s Error: %v & %v", logger.GetName(), err, accumulatedErr)
+ }
+ }
+ }
+ return accumulatedErr
+}
+
// Start processing the MultiChannelledLog
func (m *MultiChannelledLog) Start() {
m.mutex.Lock()
@@ -238,8 +273,35 @@ func (m *MultiChannelledLog) Start() {
}
m.started = true
m.mutex.Unlock()
+ paused := false
for {
+ if paused {
+ select {
+ case paused = <-m.paused:
+ if !paused {
+ m.ResetLevel()
+ }
+ case _, ok := <-m.flush:
+ if !ok {
+ m.closeLoggers()
+ return
+ }
+ m.mutex.Lock()
+ for _, logger := range m.loggers {
+ logger.Flush()
+ }
+ m.mutex.Unlock()
+ case <-m.close:
+ m.closeLoggers()
+ return
+ }
+ continue
+ }
select {
+ case paused = <-m.paused:
+ if paused && m.level < INFO {
+ m.level = INFO
+ }
case event, ok := <-m.queue:
if !ok {
m.closeLoggers()
@@ -275,7 +337,7 @@ func (m *MultiChannelledLog) LogEvent(event *Event) error {
select {
case m.queue <- event:
return nil
- case <-time.After(60 * time.Second):
+ case <-time.After(100 * time.Millisecond):
// We're blocked!
return ErrTimeout{
Name: m.name,