func NewParser(cfg *Config) (Parser, error) {
	if err := cfg.Check(); err != nil {
		return nil, fmt.Errorf("invalid config; %v", err)
	}
	var (
		p   Parser
		err error
	)
	if constructor, ok := KnownDataFormats[cfg.DataFmt]; ok {
		p, err = constructor(cfg)
	} else {
		err = fmt.Errorf("unknown parser for data format=%s", cfg.DataFmt)
	}
	return p, err
}
NewParser creates new parser based on the type the parser specified in cfg.DataFmt.
package parser
import (
	"context"
	"fmt"
	"github.com/logrange/logrange/pkg/scanner/model"
	"github.com/logrange/logrange/pkg/scanner/parser/date"
	"io"
	"strings"
)
type (
	Parser interface {
		io.Closer
		NextRecord(ctx context.Context) (*model.Record, error)
		SetStreamPos(pos int64) error
		GetStreamPos() int64
		GetStats() *Stats
	}
	fmtStats struct {
		hits map[string]int64
	}
	fileStats struct {
		Size int64
		Pos  int64
	}
	DataFormat string
	Stats struct {
		DataFormat DataFormat
		FileStats  *fileStats
		FmtStats   *fmtStats  
	}
	parserConstructorFunc func(cfg *Config) (Parser, error)
)
const (
	FmtPure   DataFormat = "pure"
	FmtText   DataFormat = "text"
	FmtK8Json DataFormat = "k8json"
	FmtLogfmt DataFormat = "logfmt"
)
const (
	unknownDateFmtName = "_%_unknown_%_"
)
var KnownDataFormats = map[DataFormat]parserConstructorFunc{
	FmtPure: func(cfg *Config) (Parser, error) {
		return NewPureParser(cfg.File, cfg.MaxRecSizeBytes)
	},
	FmtText: func(cfg *Config) (Parser, error) {
		return NewLineParser(cfg.File, date.NewDefaultParser(cfg.DateFmts...), cfg.MaxRecSizeBytes)
	},
	FmtK8Json: func(cfg *Config) (Parser, error) {
		return NewK8sJsonParser(cfg.File, cfg.MaxRecSizeBytes)
	},
	FmtLogfmt: func(cfg *Config) (Parser, error) {
		return NewLogfmtParser(cfg.File, cfg.MaxRecSizeBytes, cfg.FieldMap)
	},
}
func ToDataFormat(str string) (DataFormat, error) {
	str = strings.ToLower(strings.Trim(str, " "))
	df := DataFormat(str)
	var err error
	switch df {
	case FmtPure:
	case FmtText:
	case FmtK8Json:
	case FmtLogfmt:
	default:
		err = fmt.Errorf("unknown date format \"%s\", expecting \"%s\", \"%s\", \"%s\" or \"%s\"", str, FmtPure, FmtText, FmtK8Json, FmtLogfmt)
	}
	return df, err
}