Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: add new formatter for syslog #1608

Merged
merged 1 commit into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions daemon/logger/syslog/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ func rfc5424MicroFormatterWithTagAsAppName(p srslog.Priority, hostname, tag, con
p, 1, timestamp, hostname, tag, pid, tag, content)
return msg
}

func rfc5424MicroFormatterWithSequenceAndTagAsAppName(p srslog.Priority, hostname, tag, content string) string {
now := time.Now()
pid := os.Getpid()
msg := fmt.Sprintf("<%d>%d %d %s %s %s %d %s - %s",
p, 1, now.UnixNano(), now.Format(timeRfc5424fmt), hostname, tag, pid, tag, content)
return msg
}
5 changes: 5 additions & 0 deletions daemon/logger/syslog/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func parseLogFormat(logFmt, proto string) (srslog.Formatter, srslog.Framer, erro
return rfc5424MicroFormatterWithTagAsAppName, srslog.RFC5425MessageLengthFramer, nil
}
return rfc5424MicroFormatterWithTagAsAppName, srslog.DefaultFramer, nil
case "rfc5424micro-seq":
if proto == secureProto {
return rfc5424MicroFormatterWithSequenceAndTagAsAppName, srslog.RFC5425MessageLengthFramer, nil
}
return rfc5424MicroFormatterWithSequenceAndTagAsAppName, srslog.DefaultFramer, nil
default:
return nil, nil, ErrInvalidSyslogFormat
}
Expand Down
10 changes: 10 additions & 0 deletions daemon/logger/syslog/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ func TestParseLogFormat(t *testing.T) {
proto: "tcp",
formatter: rfc5424MicroFormatterWithTagAsAppName,
framer: srslog.DefaultFramer,
}, {
fmtTyp: "rfc5424micro-seq",
proto: "tcp",
formatter: rfc5424MicroFormatterWithSequenceAndTagAsAppName,
framer: srslog.DefaultFramer,
}, {
fmtTyp: "rfc5424micro-seq",
proto: "tcp+tls",
formatter: rfc5424MicroFormatterWithSequenceAndTagAsAppName,
framer: srslog.RFC5425MessageLengthFramer,
}, {
fmtTyp: "not support yet",
hasError: true,
Expand Down