func()

in pkg/systemlogmonitor/logwatchers/journald/log_watcher.go [94:135]


func (j *journaldWatcher) watchLoop() {
	startTimestamp := timeToJournalTimestamp(j.startTime)
	defer func() {
		if err := j.journal.Close(); err != nil {
			glog.Errorf("Failed to close journal client: %v", err)
		}
		j.tomb.Done()
	}()
	for {
		select {
		case <-j.tomb.Stopping():
			glog.Infof("Stop watching journald")
			return
		default:
		}
		// Get next log entry.
		n, err := j.journal.Next()
		if err != nil {
			glog.Errorf("Failed to get next journal entry: %v", err)
			continue
		}
		// If next reaches the end, wait for waitLogTimeout.
		if n == 0 {
			j.journal.Wait(waitLogTimeout)
			continue
		}

		entry, err := j.journal.GetEntry()
		if err != nil {
			glog.Errorf("failed to get journal entry: %v", err)
			continue
		}

		if entry.RealtimeTimestamp < startTimestamp {
			glog.V(5).Infof("Throwing away journal entry %q before start time: %v < %v",
				entry.Fields[sdjournal.SD_JOURNAL_FIELD_MESSAGE], entry.RealtimeTimestamp, startTimestamp)
			continue
		}

		j.logCh <- translate(entry)
	}
}