aboutsummaryrefslogtreecommitdiff
path: root/src/log
diff options
context:
space:
mode:
Diffstat (limited to 'src/log')
-rw-r--r--src/log/log.go3
-rw-r--r--src/log/log_test.go6
-rw-r--r--src/log/syslog/syslog.go5
-rw-r--r--src/log/syslog/syslog_test.go40
4 files changed, 38 insertions, 16 deletions
diff --git a/src/log/log.go b/src/log/log.go
index 216cfe0322..8c0f83f0d1 100644
--- a/src/log/log.go
+++ b/src/log/log.go
@@ -75,6 +75,9 @@ func (l *Logger) SetOutput(w io.Writer) {
var std = New(os.Stderr, "", LstdFlags)
+// Default returns the *Logger used by the package-level output functions.
+func Default() *Logger { return std }
+
// Cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding.
func itoa(buf *[]byte, i int, wid int) {
// Assemble decimal in reverse order.
diff --git a/src/log/log_test.go b/src/log/log_test.go
index cdccbc554d..5be8e82258 100644
--- a/src/log/log_test.go
+++ b/src/log/log_test.go
@@ -74,6 +74,12 @@ func testPrint(t *testing.T, flag int, prefix string, pattern string, useFormat
SetOutput(os.Stderr)
}
+func TestDefault(t *testing.T) {
+ if got := Default(); got != std {
+ t.Errorf("Default [%p] should be std [%p]", got, std)
+ }
+}
+
func TestAll(t *testing.T) {
for _, testcase := range tests {
testPrint(t, testcase.flag, testcase.prefix, testcase.pattern, false)
diff --git a/src/log/syslog/syslog.go b/src/log/syslog/syslog.go
index 82dd4e7dd6..97c10f31df 100644
--- a/src/log/syslog/syslog.go
+++ b/src/log/syslog/syslog.go
@@ -161,7 +161,10 @@ func (w *Writer) connect() (err error) {
var c net.Conn
c, err = net.Dial(w.network, w.raddr)
if err == nil {
- w.conn = &netConn{conn: c}
+ w.conn = &netConn{
+ conn: c,
+ local: w.network == "unixgram" || w.network == "unix",
+ }
if w.hostname == "" {
w.hostname = c.LocalAddr().String()
}
diff --git a/src/log/syslog/syslog_test.go b/src/log/syslog/syslog_test.go
index dd2f83e04f..8f472a56b7 100644
--- a/src/log/syslog/syslog_test.go
+++ b/src/log/syslog/syslog_test.go
@@ -51,12 +51,7 @@ func testableNetwork(network string) bool {
switch network {
case "unix", "unixgram":
switch runtime.GOOS {
- case "darwin", "ios":
- switch runtime.GOARCH {
- case "arm64":
- return false
- }
- case "android":
+ case "ios", "android":
return false
}
}
@@ -159,7 +154,7 @@ func TestWithSimulated(t *testing.T) {
if err != nil {
t.Fatalf("log failed: %v", err)
}
- check(t, msg, <-done)
+ check(t, msg, <-done, tr)
s.Close()
}
}
@@ -185,7 +180,7 @@ func TestFlap(t *testing.T) {
if err != nil {
t.Fatalf("log failed: %v", err)
}
- check(t, msg, <-done)
+ check(t, msg, <-done, net)
// restart the server
_, sock2, srvWG2 := startServer(net, addr, done)
@@ -198,7 +193,7 @@ func TestFlap(t *testing.T) {
if err != nil {
t.Fatalf("log failed: %v", err)
}
- check(t, msg, <-done)
+ check(t, msg, <-done, net)
s.Close()
}
@@ -258,16 +253,31 @@ func TestDial(t *testing.T) {
l.Close()
}
-func check(t *testing.T, in, out string) {
- tmpl := fmt.Sprintf("<%d>%%s %%s syslog_test[%%d]: %s\n", LOG_USER+LOG_INFO, in)
- if hostname, err := os.Hostname(); err != nil {
+func check(t *testing.T, in, out, transport string) {
+ hostname, err := os.Hostname()
+ if err != nil {
t.Error("Error retrieving hostname")
- } else {
- var parsedHostname, timestamp string
+ return
+ }
+
+ if transport == "unixgram" || transport == "unix" {
+ var month, date, ts string
var pid int
- if n, err := fmt.Sscanf(out, tmpl, &timestamp, &parsedHostname, &pid); n != 3 || err != nil || hostname != parsedHostname {
+ tmpl := fmt.Sprintf("<%d>%%s %%s %%s syslog_test[%%d]: %s\n", LOG_USER+LOG_INFO, in)
+ n, err := fmt.Sscanf(out, tmpl, &month, &date, &ts, &pid)
+ if n != 4 || err != nil {
t.Errorf("Got %q, does not match template %q (%d %s)", out, tmpl, n, err)
}
+ return
+ }
+
+ // Non-UNIX domain transports.
+ var parsedHostname, timestamp string
+ var pid int
+ tmpl := fmt.Sprintf("<%d>%%s %%s syslog_test[%%d]: %s\n", LOG_USER+LOG_INFO, in)
+ n, err := fmt.Sscanf(out, tmpl, &timestamp, &parsedHostname, &pid)
+ if n != 3 || err != nil || hostname != parsedHostname {
+ t.Errorf("Got %q, does not match template %q (%d %s)", out, tmpl, n, err)
}
}