go-syslog icon indicating copy to clipboard operation
go-syslog copied to clipboard

Add a NoFormat option (just forwarding log line)

Open fmaylinch opened this issue 3 years ago • 0 comments

I created this myself, but it could be added to the library. For logs that do not conform to standards.

// --- Dummy format that just puts the whole log line in logParts["content"] ---

// Actually, the syslog.RFC3164 format also puts the unparsed "content" field,
// but wastes times trying to parse lines that have a custom format.

var noFormat = &NoFormat{}

type NoFormat struct{}

func (f NoFormat) GetParser(line []byte) format.LogParser {
	return &noFormatParser{string(line)}
}

func (f NoFormat) GetSplitFunc() bufio.SplitFunc {
	return nil // not used
}

type noFormatParser struct {
	line string
}

func (c noFormatParser) Dump() format.LogParts {
	return format.LogParts{
		"content": string(c.line),
	}
}

func (c noFormatParser) Parse() error {
	return nil // doesn't parse anything
}

func (c noFormatParser) Location(location *time.Location) {
	// not used
}

fmaylinch avatar Dec 15 '21 13:12 fmaylinch