mcuadros / go-syslog

Syslog server library for go.
http://godoc.org/gopkg.in/mcuadros/go-syslog.v2
MIT License
523 stars 143 forks source link

Add a NoFormat option (just forwarding log line) #84

Open fmaylinch opened 2 years ago

fmaylinch commented 2 years ago

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
}