FAQ
Reviewers: golang-dev1,

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.

Search Discussions

  • Brad Fitzpatrick at Sep 9, 2013 at 7:45 pm
    LGTM


    On Mon, Sep 9, 2013 at 12:30 PM, wrote:

    Reviewers: golang-dev1,

    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/<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<golang-dev%2Bunsubscribe@googlegroups.com>
    .
    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .
    --

    ---
    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.
  • Rsc at Sep 9, 2013 at 8:17 pm
    *** Submitted as
    https://code.google.com/p/go/source/detail?r=51407182d459 ***

    log/syslog: use alternate format for logging to local syslog daemon

    Fixes issue 5803.
    Is it correct behavior? Who knows.

    R=golang-dev, bradfitz, jgc
    CC=golang-dev, jgc
    https://codereview.appspot.com/13248048


    https://codereview.appspot.com/13248048/

    --

    ---
    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.
  • Jgc at Sep 9, 2013 at 8:42 pm
    LGTM

    https://codereview.appspot.com/13248048/

    --

    ---
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedSep 9, '13 at 7:30p
activeSep 9, '13 at 8:42p
posts4
users3
websitegolang.org

3 users in discussion

Rsc: 2 posts Jgc: 1 post Brad Fitzpatrick: 1 post

People

Translate

site design / logo © 2022 Grokbase