]> Cypherpunks repositories - gostls13.git/commitdiff
log/syslog: remove RFC5424 version number for greater compatibility
authorJohn Graham-Cumming <jgc@jgc.org>
Fri, 4 Jan 2013 15:21:43 +0000 (10:21 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 4 Jan 2013 15:21:43 +0000 (10:21 -0500)
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

src/pkg/log/syslog/syslog.go
src/pkg/log/syslog/syslog_test.go

index c4ad12ffcd12dd9d641906b4b073c9f6467a3688..98b9c5f6e8773d799febe617f8584fc642803618 100644 (file)
@@ -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>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>%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
        }
index 67d7103ee44a93896217adebcca33fd26abd11bd..d1fb1b238350addd74c2af4aaee3a48a28da5532 100644 (file)
@@ -104,16 +104,15 @@ func TestUDPDial(t *testing.T) {
        }
        msg := "udp test"
        l.Info(msg)
-       expected := fmt.Sprintf("<%d>", 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, &timestamp, &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, &timestamp, &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>", 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, &timestamp, &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, &timestamp, &parsedHostname,
+                               &pid); n != 3 || err != nil || hostname != parsedHostname {
+                               t.Fatalf("'%q', didn't match '%q' (%d %s)", rcvd, test.exp,
+                                       n, err)
                        }
                }
        }