mirror of
https://github.com/golang/go
synced 2024-11-23 02:10:03 -07:00
log/syslog: remove RFC5424 version number for greater compatibility
RFC5424 specifies a version number (currently 1) after the facility and severity in a syslog message (e.g. <7>1 TIMESTAMP ...). This causes rsyslog to fail to parse syslog message because the rest of the message is not fully compliant with RFC5424. For the widest compatibility, drop the version (messages are in the RFC3164 BSD syslog format (e.g. <7>TIMESTAMP ...). Have tested this with syslog-ng, rsyslog and syslogd. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/7036050
This commit is contained in:
parent
89ec208ee8
commit
c09649890f
@ -202,14 +202,14 @@ func (w *Writer) writeString(p Priority, s string) (int, error) {
|
||||
}
|
||||
|
||||
// writeString: generates and writes a syslog formatted string. The
|
||||
// format is as follows: <PRI>1 TIMESTAMP HOSTNAME TAG[PID]: MSG
|
||||
// format is as follows: <PRI>TIMESTAMP HOSTNAME TAG[PID]: MSG
|
||||
func (n netConn) writeString(p Priority, hostname, tag, msg string) (int, error) {
|
||||
nl := ""
|
||||
if len(msg) == 0 || msg[len(msg)-1] != '\n' {
|
||||
nl = "\n"
|
||||
}
|
||||
timestamp := time.Now().Format(time.RFC3339)
|
||||
if _, err := fmt.Fprintf(n.conn, "<%d>1 %s %s %s[%d]: %s%s", p, timestamp, hostname,
|
||||
if _, err := fmt.Fprintf(n.conn, "<%d>%s %s %s[%d]: %s%s", p, timestamp, hostname,
|
||||
tag, os.Getpid(), msg, nl); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -104,16 +104,15 @@ func TestUDPDial(t *testing.T) {
|
||||
}
|
||||
msg := "udp test"
|
||||
l.Info(msg)
|
||||
expected := fmt.Sprintf("<%d>1 ", LOG_USER+LOG_INFO) + "%s %s syslog_test[%d]: udp test\n"
|
||||
expected := fmt.Sprintf("<%d>", LOG_USER+LOG_INFO) + "%s %s syslog_test[%d]: udp test\n"
|
||||
rcvd := <-done
|
||||
var parsedHostname, timestamp string
|
||||
var pid int
|
||||
if hostname, err := os.Hostname(); err != nil {
|
||||
t.Fatalf("Error retrieving hostname")
|
||||
} else {
|
||||
if n, err := fmt.Sscanf(rcvd, expected, ×tamp, &parsedHostname, &pid); n != 3 ||
|
||||
err != nil || hostname != parsedHostname {
|
||||
t.Fatalf("s.Info() = '%q', didn't match '%q'", rcvd, expected)
|
||||
if n, err := fmt.Sscanf(rcvd, expected, ×tamp, &parsedHostname, &pid); n != 3 || err != nil || hostname != parsedHostname {
|
||||
t.Fatalf("'%q', didn't match '%q' (%d, %s)", rcvd, expected, n, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,12 +145,13 @@ func TestWrite(t *testing.T) {
|
||||
t.Fatalf("WriteString() failed: %s", err)
|
||||
}
|
||||
rcvd := <-done
|
||||
test.exp = fmt.Sprintf("<%d>1 ", test.pri) + test.exp
|
||||
test.exp = fmt.Sprintf("<%d>", test.pri) + test.exp
|
||||
var parsedHostname, timestamp string
|
||||
var pid int
|
||||
if n, err := fmt.Sscanf(rcvd, test.exp, ×tamp, &parsedHostname, &pid); n != 3 ||
|
||||
err != nil || hostname != parsedHostname {
|
||||
t.Fatalf("s.Info() = '%q', didn't match '%q'", rcvd, test.exp)
|
||||
if n, err := fmt.Sscanf(rcvd, test.exp, ×tamp, &parsedHostname,
|
||||
&pid); n != 3 || err != nil || hostname != parsedHostname {
|
||||
t.Fatalf("'%q', didn't match '%q' (%d %s)", rcvd, test.exp,
|
||||
n, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user