mirror of
https://github.com/mjl-/mox.git
synced 2025-07-10 10:34:40 +03:00
switch to slog.Logger for logging, for easier reuse of packages by external software
we don't want external software to include internal details like mlog. slog.Logger is/will be the standard. we still have mlog for its helper functions, and its handler that logs in concise logfmt used by mox. packages that are not meant for reuse still pass around mlog.Log for convenience. we use golang.org/x/exp/slog because we also support the previous Go toolchain version. with the next Go release, we'll switch to the builtin slog.
This commit is contained in:
@ -14,6 +14,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/slog"
|
||||
|
||||
"github.com/mjl-/mox/dns"
|
||||
"github.com/mjl-/mox/imapclient"
|
||||
"github.com/mjl-/mox/mlog"
|
||||
@ -30,7 +32,7 @@ func tcheck(t *testing.T, err error, errmsg string) {
|
||||
}
|
||||
|
||||
func TestDeliver(t *testing.T) {
|
||||
xlog := mlog.New("integration")
|
||||
log := mlog.New("integration", nil)
|
||||
mlog.Logfmt = true
|
||||
|
||||
hostname, err := os.Hostname()
|
||||
@ -129,7 +131,7 @@ This is the message.
|
||||
`, mailfrom, rcptto)
|
||||
msg = strings.ReplaceAll(msg, "\n", "\r\n")
|
||||
auth := []sasl.Client{sasl.NewClientPlain(mailfrom, password)}
|
||||
c, err := smtpclient.New(mox.Context, xlog, conn, smtpclient.TLSSkip, false, ourHostname, dns.Domain{ASCII: desthost}, smtpclient.Opts{Auth: auth})
|
||||
c, err := smtpclient.New(mox.Context, log.Logger, conn, smtpclient.TLSSkip, false, ourHostname, dns.Domain{ASCII: desthost}, smtpclient.Opts{Auth: auth})
|
||||
tcheck(t, err, "smtp hello")
|
||||
err = c.Deliver(mox.Context, mailfrom, rcptto, int64(len(msg)), strings.NewReader(msg), false, false, false)
|
||||
tcheck(t, err, "deliver with smtp")
|
||||
@ -142,35 +144,35 @@ This is the message.
|
||||
tcheck(t, err, "dial submission")
|
||||
defer conn.Close()
|
||||
|
||||
xlog.Print("submitting email to moxacmepebble, waiting for imap notification at moxmail2")
|
||||
log.Print("submitting email to moxacmepebble, waiting for imap notification at moxmail2")
|
||||
t0 := time.Now()
|
||||
deliver(true, true, "moxmail2.mox2.example:993", "moxtest2@mox2.example", "accountpass4321", func() {
|
||||
submit(true, "moxtest1@mox1.example", "accountpass1234", "moxacmepebble.mox1.example:465", "moxtest2@mox2.example")
|
||||
})
|
||||
xlog.Print("success", mlog.Field("duration", time.Since(t0)))
|
||||
log.Print("success", slog.Duration("duration", time.Since(t0)))
|
||||
|
||||
xlog.Print("submitting email to moxmail2, waiting for imap notification at moxacmepebble")
|
||||
log.Print("submitting email to moxmail2, waiting for imap notification at moxacmepebble")
|
||||
t0 = time.Now()
|
||||
deliver(true, true, "moxacmepebble.mox1.example:993", "moxtest1@mox1.example", "accountpass1234", func() {
|
||||
submit(true, "moxtest2@mox2.example", "accountpass4321", "moxmail2.mox2.example:465", "moxtest1@mox1.example")
|
||||
})
|
||||
xlog.Print("success", mlog.Field("duration", time.Since(t0)))
|
||||
log.Print("success", slog.Duration("duration", time.Since(t0)))
|
||||
|
||||
xlog.Print("submitting email to postfix, waiting for imap notification at moxacmepebble")
|
||||
log.Print("submitting email to postfix, waiting for imap notification at moxacmepebble")
|
||||
t0 = time.Now()
|
||||
deliver(false, true, "moxacmepebble.mox1.example:993", "moxtest1@mox1.example", "accountpass1234", func() {
|
||||
submit(true, "moxtest1@mox1.example", "accountpass1234", "moxacmepebble.mox1.example:465", "root@postfix.example")
|
||||
})
|
||||
xlog.Print("success", mlog.Field("duration", time.Since(t0)))
|
||||
log.Print("success", slog.Duration("duration", time.Since(t0)))
|
||||
|
||||
xlog.Print("submitting email to localserve")
|
||||
log.Print("submitting email to localserve")
|
||||
t0 = time.Now()
|
||||
deliver(false, false, "localserve.mox1.example:1143", "mox@localhost", "moxmoxmox", func() {
|
||||
submit(false, "mox@localhost", "moxmoxmox", "localserve.mox1.example:1587", "moxtest1@mox1.example")
|
||||
})
|
||||
xlog.Print("success", mlog.Field("duration", time.Since(t0)))
|
||||
log.Print("success", slog.Duration("duration", time.Since(t0)))
|
||||
|
||||
xlog.Print("submitting email to localserve")
|
||||
log.Print("submitting email to localserve")
|
||||
t0 = time.Now()
|
||||
deliver(false, false, "localserve.mox1.example:1143", "mox@localhost", "moxmoxmox", func() {
|
||||
cmd := exec.Command("go", "run", ".", "sendmail", "mox@localhost")
|
||||
@ -182,8 +184,8 @@ a message.
|
||||
var out strings.Builder
|
||||
cmd.Stdout = &out
|
||||
err := cmd.Run()
|
||||
xlog.Print("sendmail", mlog.Field("output", out.String()))
|
||||
log.Print("sendmail", slog.String("output", out.String()))
|
||||
tcheck(t, err, "sendmail")
|
||||
})
|
||||
xlog.Print("success", mlog.Field("duration", time.Since(t0)))
|
||||
log.Print("success", slog.Any("duration", time.Since(t0)))
|
||||
}
|
||||
|
Reference in New Issue
Block a user