Message:
Hello golang-dev@googlegroups.com (cc: jgc@jgc.org),
I'd like you to review this change to
https://code.google.com/p/go/
Description:
log/syslog: use alternate format for logging to local syslog daemon
Fixes issue 5803.
Is it correct behavior? Who knows.
Please review this at https://codereview.appspot.com/13248048/
Affected files (+16, -5 lines):
M src/pkg/log/syslog/syslog.go
M src/pkg/log/syslog/syslog_unix.go
Index: src/pkg/log/syslog/syslog.go
===================================================================
--- a/src/pkg/log/syslog/syslog.go
+++ b/src/pkg/log/syslog/syslog.go
@@ -103,7 +103,8 @@
}
type netConn struct {
- conn net.Conn
+ local bool
+ conn net.Conn
}
// New establishes a new connection to the system log daemon. Each
@@ -163,7 +164,7 @@
var c net.Conn
c, err = net.Dial(w.network, w.raddr)
if err == nil {
- w.conn = netConn{c}
+ w.conn = &netConn{conn: c}
if w.hostname == "" {
w.hostname = c.LocalAddr().String()
}
@@ -282,7 +283,17 @@
return len(msg), nil
}
-func (n netConn) writeString(p Priority, hostname, tag, msg, nl string)
error {
+func (n *netConn) writeString(p Priority, hostname, tag, msg, nl string)
error {
+ if n.local {
+ // Compared to the network form below, the changes are:
+ // 1. Use time.Stamp instead of time.RFC3339.
+ // 2. Drop the hostname field from the Fprintf.
+ timestamp := time.Now().Format(time.Stamp)
+ _, err := fmt.Fprintf(n.conn, "<%d>%s %s[%d]: %s%s",
+ p, timestamp,
+ tag, os.Getpid(), msg, nl)
+ return err
+ }
timestamp := time.Now().Format(time.RFC3339)
_, err := fmt.Fprintf(n.conn, "<%d>%s %s %s[%d]: %s%s",
p, timestamp, hostname,
@@ -290,7 +301,7 @@
return err
}
-func (n netConn) close() error {
+func (n *netConn) close() error {
return n.conn.Close()
}
Index: src/pkg/log/syslog/syslog_unix.go
===================================================================
--- a/src/pkg/log/syslog/syslog_unix.go
+++ b/src/pkg/log/syslog/syslog_unix.go
@@ -23,7 +23,7 @@
if err != nil {
continue
} else {
- return netConn{conn}, nil
+ return &netConn{conn: conn, local: true}, nil
}
}
}
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.