summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2021-08-29 21:34:02 -0600
committerBrian Picciano <mediocregopher@gmail.com>2021-08-29 21:34:02 -0600
commit1608ca742584e83453b0ef52aa0e71661eb15666 (patch)
treecb86e60140548678b919f07bb06367d817218a41
parentbf40fa3868dc40c94e649df22179428061039b9a (diff)
better logging in srv when fake Mailer is used
-rw-r--r--Makefile1
-rw-r--r--srv/cmd/mediocre-blog/main.go4
-rw-r--r--srv/mailinglist/mailer.go20
3 files changed, 22 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index fb1e657..ef9130a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,3 @@
-
all:
nix-build -A entrypoint --arg baseConfig '(import ./config.nix) // { staticProxyURL = ""; }'
diff --git a/srv/cmd/mediocre-blog/main.go b/srv/cmd/mediocre-blog/main.go
index 7d3f722..5d0d790 100644
--- a/srv/cmd/mediocre-blog/main.go
+++ b/srv/cmd/mediocre-blog/main.go
@@ -74,8 +74,8 @@ func main() {
var mailer mailinglist.Mailer
if mailerParams.SMTPAddr == "" {
- logger.Info(ctx, "-smtp-addr not given, using NullMailer")
- mailer = mailinglist.NullMailer
+ logger.Info(ctx, "-smtp-addr not given, using a fake Mailer")
+ mailer = mailinglist.NewLogMailer(logger.WithNamespace("fake-mailer"))
} else {
mailer = mailinglist.NewMailer(mailerParams)
}
diff --git a/srv/mailinglist/mailer.go b/srv/mailinglist/mailer.go
index b65ccb8..e58ea17 100644
--- a/srv/mailinglist/mailer.go
+++ b/srv/mailinglist/mailer.go
@@ -9,6 +9,7 @@ import (
"github.com/emersion/go-smtp"
"github.com/mediocregopher/blog.mediocregopher.com/srv/cfg"
"github.com/mediocregopher/mediocre-go-lib/v2/mctx"
+ "github.com/mediocregopher/mediocre-go-lib/v2/mlog"
)
// Mailer is used to deliver emails to arbitrary recipients.
@@ -16,6 +17,25 @@ type Mailer interface {
Send(to, subject, body string) error
}
+type logMailer struct {
+ logger *mlog.Logger
+}
+
+// NewLogMailer returns a Mailer instance which will not actually send any
+// emails, it will only log to the given Logger when Send is called.
+func NewLogMailer(logger *mlog.Logger) Mailer {
+ return &logMailer{logger: logger}
+}
+
+func (l *logMailer) Send(to, subject, body string) error {
+ ctx := mctx.Annotate(context.Background(),
+ "to", to,
+ "subject", subject,
+ )
+ l.logger.Info(ctx, "would have sent email")
+ return nil
+}
+
// NullMailer acts as a Mailer but actually just does nothing.
var NullMailer = nullMailer{}