func()

in pkg/accesslog/runner.go [153:185]


func (r *Runner) buildProtocolLogs(protocols chan common.ProtocolLog, batch *sender.BatchLogs) {
	delayAppends := make([]common.ProtocolLog, 0)
	for {
		select {
		case protocolLog := <-protocols:
			connection, kernelLogs, protocolLogs, delay := r.buildProtocolLog(protocolLog)
			if log.Enable(logrus.DebugLevel) {
				kernelLogCount := len(protocolLog.RelateKernelLogs())
				var conID, randomID uint64
				if kernelLogCount > 0 {
					conID, randomID = protocolLog.RelateKernelLogs()[0].GetConnectionID(),
						protocolLog.RelateKernelLogs()[0].GetRandomID()
				}
				log.Debugf("building protocol log result, connetaion ID: %d, random ID: %d, connection exist: %t, delay: %t",
					conID, randomID, connection != nil, delay)
			}
			if connection != nil && len(kernelLogs) > 0 && protocolLogs != nil {
				batch.AppendProtocolLog(connection, kernelLogs, protocolLogs)
			} else if delay {
				delayAppends = append(delayAppends, protocolLog)
			}
		default:
			for _, delayAppend := range delayAppends {
				select {
				case protocols <- delayAppend:
				default:
					return
				}
			}
			return
		}
	}
}