1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

Improve the readability of some log messages

This patch contains a few changes to logging messages, to improve log
readability.

While at it, an obsolete TODO in the SMTP courier is removed.
This commit is contained in:
Alberto Bertogli
2016-10-24 10:49:49 +01:00
parent 60a7932bd3
commit 1bc111f783
6 changed files with 41 additions and 45 deletions

View File

@@ -63,11 +63,11 @@ func (l *Logger) Listening(a string) {
}
func (l *Logger) Auth(netAddr net.Addr, user string, successful bool) {
res := "successful"
res := "succeeded"
if !successful {
res = "failed"
}
msg := fmt.Sprintf("%s authentication %s for %s\n", netAddr, res, user)
msg := fmt.Sprintf("%s auth %s for %s\n", netAddr, res, user)
l.printf(msg)
authLog.Debugf(msg)
}
@@ -89,21 +89,21 @@ func (l *Logger) Queued(netAddr net.Addr, from string, to []string, id string) {
func (l *Logger) SendAttempt(id, from, to string, err error, permanent bool) {
if err == nil {
l.printf("%s from=%s to=%s sent successfully\n", id, from, to)
l.printf("%s from=%s to=%s sent\n", id, from, to)
} else {
t := "(temporary)"
if permanent {
t = "(permanent)"
}
l.printf("%s from=%s to=%s sent failed %s: %v\n", id, from, to, t, err)
l.printf("%s from=%s to=%s failed %s: %v\n", id, from, to, t, err)
}
}
func (l *Logger) QueueLoop(id string, nextDelay time.Duration) {
func (l *Logger) QueueLoop(id, from string, nextDelay time.Duration) {
if nextDelay > 0 {
l.printf("%s completed loop, next in %v\n", id, nextDelay)
l.printf("%s from=%s completed loop, next in %v\n", id, from, nextDelay)
} else {
l.printf("%s all done\n", id)
l.printf("%s from=%s all done\n", id, from)
}
}
@@ -130,6 +130,6 @@ func SendAttempt(id, from, to string, err error, permanent bool) {
Default.SendAttempt(id, from, to, err, permanent)
}
func QueueLoop(id string, nextDelay time.Duration) {
Default.QueueLoop(id, nextDelay)
func QueueLoop(id, from string, nextDelay time.Duration) {
Default.QueueLoop(id, from, nextDelay)
}

View File

@@ -32,11 +32,11 @@ func TestLogger(t *testing.T) {
buf.Reset()
l.Auth(netAddr, "user@domain", false)
expect(t, buf, "1.2.3.4:4321 authentication failed for user@domain")
expect(t, buf, "1.2.3.4:4321 auth failed for user@domain")
buf.Reset()
l.Auth(netAddr, "user@domain", true)
expect(t, buf, "1.2.3.4:4321 authentication successful for user@domain")
expect(t, buf, "1.2.3.4:4321 auth succeeded for user@domain")
buf.Reset()
l.Rejected(netAddr, "from", []string{"to1", "to2"}, "error")
@@ -48,23 +48,23 @@ func TestLogger(t *testing.T) {
buf.Reset()
l.SendAttempt("qid", "from", "to", nil, false)
expect(t, buf, "qid from=from to=to sent successfully")
expect(t, buf, "qid from=from to=to sent")
buf.Reset()
l.SendAttempt("qid", "from", "to", fmt.Errorf("error"), false)
expect(t, buf, "qid from=from to=to sent failed (temporary): error")
expect(t, buf, "qid from=from to=to failed (temporary): error")
buf.Reset()
l.SendAttempt("qid", "from", "to", fmt.Errorf("error"), true)
expect(t, buf, "qid from=from to=to sent failed (permanent): error")
expect(t, buf, "qid from=from to=to failed (permanent): error")
buf.Reset()
l.QueueLoop("qid", 17*time.Second)
expect(t, buf, "qid completed loop, next in 17s")
l.QueueLoop("qid", "from", 17*time.Second)
expect(t, buf, "qid from=from completed loop, next in 17s")
buf.Reset()
l.QueueLoop("qid", 0)
expect(t, buf, "qid all done")
l.QueueLoop("qid", "from", 0)
expect(t, buf, "qid from=from all done")
buf.Reset()
}
@@ -79,11 +79,11 @@ func TestDefault(t *testing.T) {
buf.Reset()
Auth(netAddr, "user@domain", false)
expect(t, buf, "1.2.3.4:4321 authentication failed for user@domain")
expect(t, buf, "1.2.3.4:4321 auth failed for user@domain")
buf.Reset()
Auth(netAddr, "user@domain", true)
expect(t, buf, "1.2.3.4:4321 authentication successful for user@domain")
expect(t, buf, "1.2.3.4:4321 auth succeeded for user@domain")
buf.Reset()
Rejected(netAddr, "from", []string{"to1", "to2"}, "error")
@@ -95,22 +95,22 @@ func TestDefault(t *testing.T) {
buf.Reset()
SendAttempt("qid", "from", "to", nil, false)
expect(t, buf, "qid from=from to=to sent successfully")
expect(t, buf, "qid from=from to=to sent")
buf.Reset()
SendAttempt("qid", "from", "to", fmt.Errorf("error"), false)
expect(t, buf, "qid from=from to=to sent failed (temporary): error")
expect(t, buf, "qid from=from to=to failed (temporary): error")
buf.Reset()
SendAttempt("qid", "from", "to", fmt.Errorf("error"), true)
expect(t, buf, "qid from=from to=to sent failed (permanent): error")
expect(t, buf, "qid from=from to=to failed (permanent): error")
buf.Reset()
QueueLoop("qid", 17*time.Second)
expect(t, buf, "qid completed loop, next in 17s")
QueueLoop("qid", "from", 17*time.Second)
expect(t, buf, "qid from=from completed loop, next in 17s")
buf.Reset()
QueueLoop("qid", 0)
expect(t, buf, "qid all done")
QueueLoop("qid", "from", 0)
expect(t, buf, "qid from=from all done")
buf.Reset()
}