mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 17:44:35 +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:
16
junk.go
16
junk.go
@ -93,7 +93,7 @@ func cmdJunkTrain(c *cmd) {
|
||||
}
|
||||
a.SetLogLevel()
|
||||
|
||||
f := must(junk.NewFilter(context.Background(), mlog.New("junktrain"), a.params, a.databasePath, a.bloomfilterPath))
|
||||
f := must(junk.NewFilter(context.Background(), c.log, a.params, a.databasePath, a.bloomfilterPath))
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
log.Printf("closing junk filter: %v", err)
|
||||
@ -122,7 +122,7 @@ func cmdJunkCheck(c *cmd) {
|
||||
}
|
||||
a.SetLogLevel()
|
||||
|
||||
f := must(junk.OpenFilter(context.Background(), mlog.New("junkcheck"), a.params, a.databasePath, a.bloomfilterPath, false))
|
||||
f := must(junk.OpenFilter(context.Background(), c.log, a.params, a.databasePath, a.bloomfilterPath, false))
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
log.Printf("closing junk filter: %v", err)
|
||||
@ -146,7 +146,7 @@ func cmdJunkTest(c *cmd) {
|
||||
}
|
||||
a.SetLogLevel()
|
||||
|
||||
f := must(junk.OpenFilter(context.Background(), mlog.New("junktest"), a.params, a.databasePath, a.bloomfilterPath, false))
|
||||
f := must(junk.OpenFilter(context.Background(), c.log, a.params, a.databasePath, a.bloomfilterPath, false))
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
log.Printf("closing junk filter: %v", err)
|
||||
@ -202,7 +202,7 @@ messages are shuffled, with optional random seed.`
|
||||
}
|
||||
a.SetLogLevel()
|
||||
|
||||
f := must(junk.NewFilter(context.Background(), mlog.New("junkanalyze"), a.params, a.databasePath, a.bloomfilterPath))
|
||||
f := must(junk.NewFilter(context.Background(), c.log, a.params, a.databasePath, a.bloomfilterPath))
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
log.Printf("closing junk filter: %v", err)
|
||||
@ -293,7 +293,7 @@ func cmdJunkPlay(c *cmd) {
|
||||
}
|
||||
a.SetLogLevel()
|
||||
|
||||
f := must(junk.NewFilter(context.Background(), mlog.New("junkplay"), a.params, a.databasePath, a.bloomfilterPath))
|
||||
f := must(junk.NewFilter(context.Background(), c.log, a.params, a.databasePath, a.bloomfilterPath))
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
log.Printf("closing junk filter: %v", err)
|
||||
@ -310,8 +310,6 @@ func cmdJunkPlay(c *cmd) {
|
||||
|
||||
var nbad, nnodate, nham, nspam, nsent int
|
||||
|
||||
jlog := mlog.New("junkplay")
|
||||
|
||||
scanDir := func(dir string, ham, sent bool) {
|
||||
for _, name := range listDir(dir) {
|
||||
path := filepath.Join(dir, name)
|
||||
@ -319,7 +317,7 @@ func cmdJunkPlay(c *cmd) {
|
||||
xcheckf(err, "open %q", path)
|
||||
fi, err := mf.Stat()
|
||||
xcheckf(err, "stat %q", path)
|
||||
p, err := message.EnsurePart(jlog, false, mf, fi.Size())
|
||||
p, err := message.EnsurePart(c.log.Logger, false, mf, fi.Size())
|
||||
if err != nil {
|
||||
nbad++
|
||||
if err := mf.Close(); err != nil {
|
||||
@ -399,7 +397,7 @@ func cmdJunkPlay(c *cmd) {
|
||||
}()
|
||||
fi, err := mf.Stat()
|
||||
xcheckf(err, "stat %q", path)
|
||||
p, err := message.EnsurePart(jlog, false, mf, fi.Size())
|
||||
p, err := message.EnsurePart(c.log.Logger, false, mf, fi.Size())
|
||||
if err != nil {
|
||||
log.Printf("bad sent message %q: %s", path, err)
|
||||
return
|
||||
|
Reference in New Issue
Block a user