code: func (m *logMultiplexer) Next() (chanIndex int, log *logpb.LogEntry, err error) {
  	if m.heads == nil {
  		// initialization
  		m.heads = make([]logAndErr, len(m.Chans))
  		for i := range m.heads {
  			m.heads[i] = <-m.Chans[i].c
  		}
  	}
  
  	// Choose the earliest one.
  	// Note: using heap is overkill here.
  	// Most of the time we deal with only two logs.
  	earliest := -1
  	earliestTime := time.Time{}
  	for i, h := range m.heads {
  		if h.err == io.EOF {
  			continue
  		}
  		if h.err != nil {
  			return 0, nil, h.err
  		}
  
  		curTime := m.Chans[i].start
  		if h.TimeOffset != nil {
  			offset, err := ptypes.Duration(h.TimeOffset)
  			if err != nil {
  				return 0, nil, err
  			}
  			curTime = curTime.Add(offset)
  		}
  
  		isEarlier := earliest == -1 ||
  			curTime.Before(earliestTime) ||
  			(curTime.Equal(earliestTime) && h.PrefixIndex < m.heads[earliest].PrefixIndex)
  		if isEarlier {
  			earliest = i
  			earliestTime = curTime
  		}
  	}
  	if earliest == -1 {
  		// all finished
  		return 0, nil, io.EOF
  	}
  
  	// Call f and replace the entry with the freshest one from the same
  	// channel.
  	earliestEntry := m.heads[earliest].LogEntry
  	m.heads[earliest] = <-m.Chans[earliest].c
  	return earliest, earliestEntry, nil
  }
docs: // Next returns the next log entry.
  // Returns io.EOF if there is no next log entry.