Skip to content

Commit b79ba10

Browse files
author
Matthew Fisher
committed
fix(logger): add back message tag
without the tag, the first word from the logs was missing. Without this change: 2014-07-23 16:29:05 oblong-duckling[worker.1]: world with this change: 2014-07-23 16:38:19 oblong-duckling[worker.1]: hello world
1 parent c5b9697 commit b79ba10

4 files changed

Lines changed: 98 additions & 97 deletions

File tree

logger/syslog/filehandler_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
package syslog
22

33
import (
4-
"testing"
5-
"time"
4+
"testing"
5+
"time"
66
)
77

8-
type TestLogger struct {}
8+
type TestLogger struct{}
99

10-
func (tl TestLogger) Print(...interface{}) {}
10+
func (tl TestLogger) Print(...interface{}) {}
1111
func (tl TestLogger) Printf(format string, v ...interface{}) {}
12-
func (tl TestLogger) Println(...interface{}) {}
12+
func (tl TestLogger) Println(...interface{}) {}
1313

1414
func TestNewFileHandler(t *testing.T) {
15-
fh := NewFileHandler("", 1, func (m *Message) bool {return true}, true)
16-
if fh == nil {
17-
t.Errorf("expected filehandler, got nil")
18-
}
15+
fh := NewFileHandler("", 1, func(m *Message) bool { return true }, true)
16+
if fh == nil {
17+
t.Errorf("expected filehandler, got nil")
18+
}
1919
}
2020

2121
func TestSetLogger(t *testing.T) {
22-
tl := TestLogger{}
23-
fh := NewFileHandler("", 1, func (m *Message) bool {return true}, true)
24-
fh.SetLogger(tl)
25-
if fh.l != tl {
26-
t.Errorf("expected the logger to be set")
27-
}
22+
tl := TestLogger{}
23+
fh := NewFileHandler("", 1, func(m *Message) bool { return true }, true)
24+
fh.SetLogger(tl)
25+
if fh.l != tl {
26+
t.Errorf("expected the logger to be set")
27+
}
2828
}
2929

3030
func TestHandle(t *testing.T) {
31-
fh := NewFileHandler("/tmp/test", 1, func (m *Message) bool {return true}, true)
32-
handle := fh.Handle(&Message{time.Now(), nil, 0, 0, time.Now(), "localhost", "test", "message", "", ""})
33-
if handle == nil {
34-
t.Errorf("expected a handle, got nil")
35-
}
31+
fh := NewFileHandler("/tmp/test", 1, func(m *Message) bool { return true }, true)
32+
handle := fh.Handle(&Message{time.Now(), nil, 0, 0, time.Now(), "localhost", "test", "message", "", ""})
33+
if handle == nil {
34+
t.Errorf("expected a handle, got nil")
35+
}
3636
}

logger/syslog/message.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ func (m *Message) NetSrc() string {
3636
func (m *Message) String() string {
3737
timeLayout := "2006-01-02 15:04:05"
3838
return fmt.Sprintf(
39-
"%s %s %s",
39+
"%s %s %s%s",
4040
m.Time.Format(timeLayout),
4141
m.Hostname,
42+
m.Tag,
4243
m.Content,
4344
)
4445
}

logger/syslog/message_test.go

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
11
package syslog
22

33
import (
4-
"net"
5-
"testing"
6-
"time"
4+
"net"
5+
"testing"
6+
"time"
77
)
88

99
func TestMessageNetSrc(t *testing.T) {
10-
tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234")
10+
tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234")
1111

12-
if err != nil {
13-
t.Errorf("could not resolve TCP address")
14-
}
12+
if err != nil {
13+
t.Errorf("could not resolve TCP address")
14+
}
1515

16-
m := &Message{time.Now(), tcpAddress, 0, 0, time.Now(), "", "", "", "", ""}
17-
if m.NetSrc() != "127.0.0.1" {
18-
t.Errorf("expected 127.0.0.1, got ", m.NetSrc())
19-
}
16+
m := &Message{time.Now(), tcpAddress, 0, 0, time.Now(), "", "", "", "", ""}
17+
if m.NetSrc() != "127.0.0.1" {
18+
t.Errorf("expected 127.0.0.1, got ", m.NetSrc())
19+
}
2020

21-
udpAddress, err := net.ResolveUDPAddr("udp", "localhost:1234")
21+
udpAddress, err := net.ResolveUDPAddr("udp", "localhost:1234")
2222

23-
if err != nil {
24-
t.Errorf("could not resolve UDP address")
25-
}
23+
if err != nil {
24+
t.Errorf("could not resolve UDP address")
25+
}
2626

27-
m.Source = udpAddress
28-
if m.NetSrc() != "127.0.0.1" {
29-
t.Errorf("expected 127.0.0.1, got ", m.NetSrc())
30-
}
27+
m.Source = udpAddress
28+
if m.NetSrc() != "127.0.0.1" {
29+
t.Errorf("expected 127.0.0.1, got ", m.NetSrc())
30+
}
3131

32-
unixAddress, err := net.ResolveUnixAddr("unix", "/tmp/str")
32+
unixAddress, err := net.ResolveUnixAddr("unix", "/tmp/str")
3333

34-
if err != nil {
35-
t.Errorf("could not resolve unix address")
36-
}
34+
if err != nil {
35+
t.Errorf("could not resolve unix address")
36+
}
3737

38-
m.Source = unixAddress
39-
if m.NetSrc() != "/tmp/str" {
40-
t.Errorf("expected /tmp/str, got ", m.NetSrc())
41-
}
38+
m.Source = unixAddress
39+
if m.NetSrc() != "/tmp/str" {
40+
t.Errorf("expected /tmp/str, got ", m.NetSrc())
41+
}
4242

43-
unknownAddress, err := net.ResolveIPAddr("ip4", "localhost")
43+
unknownAddress, err := net.ResolveIPAddr("ip4", "localhost")
4444

45-
if err != nil {
46-
t.Errorf("could not resolve unknown address")
47-
}
45+
if err != nil {
46+
t.Errorf("could not resolve unknown address")
47+
}
4848

49-
m.Source = unknownAddress
50-
if m.NetSrc() != "127.0.0.1" {
51-
t.Errorf("expected 127.0.0.1, got ", m.NetSrc())
52-
}
49+
m.Source = unknownAddress
50+
if m.NetSrc() != "127.0.0.1" {
51+
t.Errorf("expected 127.0.0.1, got ", m.NetSrc())
52+
}
5353
}
5454

5555
func TestMessageFormat(t *testing.T) {
56-
tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234")
57-
58-
if err != nil {
59-
t.Errorf("could not resolve TCP address")
60-
}
61-
62-
m := &Message{
63-
time.Now(),
64-
tcpAddress,
65-
0,
66-
0,
67-
time.Now(),
68-
"localhost",
69-
"TEST",
70-
"hello world",
71-
"",
72-
"",
73-
}
74-
75-
timeLayout := "2006-01-02 15:04:05"
76-
expectedOutput := m.Time.Format(timeLayout) + " localhost hello world"
77-
if m.String() != expectedOutput {
78-
t.Errorf("expected '" + expectedOutput + "', got '" + m.String() + "'.")
79-
}
56+
tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234")
57+
58+
if err != nil {
59+
t.Errorf("could not resolve TCP address")
60+
}
61+
62+
m := &Message{
63+
time.Now(),
64+
tcpAddress,
65+
0,
66+
0,
67+
time.Now(),
68+
"localhost",
69+
"TEST",
70+
"hello world",
71+
"",
72+
"",
73+
}
74+
75+
timeLayout := "2006-01-02 15:04:05"
76+
expectedOutput := m.Time.Format(timeLayout) + " localhost TESThello world"
77+
if m.String() != expectedOutput {
78+
t.Errorf("expected '" + expectedOutput + "', got '" + m.String() + "'.")
79+
}
8080
}

logger/syslog/priority_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
package syslog
22

33
import (
4-
"testing"
4+
"testing"
55
)
66

77
func TestFacilityToString(t *testing.T) {
8-
var fac Facility = 100
9-
if fac.String() != "unknown" {
10-
t.Errorf("facility != unknown; got %s", fac.String())
11-
}
12-
fac = 20
13-
if fac.String() != "local4" {
14-
t.Errorf("facility != local4; got %s", fac.String())
15-
}
8+
var fac Facility = 100
9+
if fac.String() != "unknown" {
10+
t.Errorf("facility != unknown; got %s", fac.String())
11+
}
12+
fac = 20
13+
if fac.String() != "local4" {
14+
t.Errorf("facility != local4; got %s", fac.String())
15+
}
1616
}
1717

1818
func TestSeverityToString(t *testing.T) {
19-
var sev Severity = 100
20-
if sev.String() != "unknown" {
21-
t.Errorf("severity != unknown; got %s", sev.String())
22-
}
23-
sev = 5
24-
if sev.String() != "notice" {
25-
t.Errorf("severity != local4; got %s", sev.String())
26-
}
19+
var sev Severity = 100
20+
if sev.String() != "unknown" {
21+
t.Errorf("severity != unknown; got %s", sev.String())
22+
}
23+
sev = 5
24+
if sev.String() != "notice" {
25+
t.Errorf("severity != local4; got %s", sev.String())
26+
}
2727
}

0 commit comments

Comments
 (0)