Exemplo n.º 1
0
func (h *Harvester) newLineProcessor() (processor.LineProcessor, error) {

	readerConfig := h.newLogFileReaderConfig()

	var p processor.LineProcessor
	var err error

	fileReader, err := reader.NewLogFileReader(h.file, readerConfig, h.done)
	if err != nil {
		return nil, err
	}

	p, err = processor.NewLineEncoder(fileReader, h.encoding, h.config.BufferSize)
	if err != nil {
		return nil, err
	}

	if h.config.JSON != nil {
		p = processor.NewJSONProcessor(p, h.config.JSON)
	}

	p = processor.NewStripNewline(p)
	if h.config.Multiline != nil {
		p, err = processor.NewMultiline(p, "\n", h.config.MaxBytes, h.config.Multiline)
		if err != nil {
			return nil, err
		}
	}

	return processor.NewLimitProcessor(p, h.config.MaxBytes), nil
}
Exemplo n.º 2
0
Arquivo: log.go Projeto: yhyang1/beats
func createLineProcessor(
	in source.FileSource,
	codec encoding.Encoding,
	bufferSize int,
	maxBytes int,
	readerConfig reader.LogFileReaderConfig,
	jsonConfig *processor.JSONConfig,
	mlrConfig *processor.MultilineConfig,
	done chan struct{},
) (processor.LineProcessor, error) {
	var p processor.LineProcessor
	var err error

	fileReader, err := reader.NewLogFileReader(in, readerConfig, done)
	if err != nil {
		return nil, err
	}

	p, err = processor.NewLineEncoder(fileReader, codec, bufferSize)
	if err != nil {
		return nil, err
	}

	if jsonConfig != nil {
		p = processor.NewJSONProcessor(p, jsonConfig)
	}

	p = processor.NewStripNewline(p)
	if mlrConfig != nil {
		p, err = processor.NewMultiline(p, "\n", maxBytes, mlrConfig)
		if err != nil {
			return nil, err
		}
	}

	return processor.NewLimitProcessor(p, maxBytes), nil
}