mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 13:44:37 +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:
@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/slog"
|
||||
|
||||
"github.com/mjl-/mox/dns"
|
||||
"github.com/mjl-/mox/mlog"
|
||||
"github.com/mjl-/mox/mox-"
|
||||
@ -13,8 +15,8 @@ import (
|
||||
)
|
||||
|
||||
func mtastsPolicyHandle(w http.ResponseWriter, r *http.Request) {
|
||||
log := func() *mlog.Log {
|
||||
return xlog.WithContext(r.Context())
|
||||
log := func() mlog.Log {
|
||||
return pkglog.WithContext(r.Context())
|
||||
}
|
||||
|
||||
host := strings.ToLower(r.Host)
|
||||
@ -30,7 +32,7 @@ func mtastsPolicyHandle(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
domain, err := dns.ParseDomain(host)
|
||||
if err != nil {
|
||||
log().Errorx("mtasts policy request: bad domain", err, mlog.Field("host", host))
|
||||
log().Errorx("mtasts policy request: bad domain", err, slog.String("host", host))
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
@ -51,7 +53,7 @@ func mtastsPolicyHandle(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
d, err := dns.ParseDomain(s)
|
||||
if err != nil {
|
||||
log().Errorx("bad domain in mtasts config", err, mlog.Field("domain", s))
|
||||
log().Errorx("bad domain in mtasts config", err, slog.String("domain", s))
|
||||
http.Error(w, "500 - internal server error - invalid domain in configuration", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user