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:
@ -5,6 +5,8 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"golang.org/x/exp/slog"
|
||||
|
||||
"github.com/mjl-/mox/mlog"
|
||||
)
|
||||
|
||||
@ -14,7 +16,7 @@ import (
|
||||
// ensure the file is written on disk. Callers should also sync the directory of
|
||||
// the destination file, but may want to do that after linking/copying multiple
|
||||
// files. If dst was created and an error occurred, it is removed.
|
||||
func LinkOrCopy(log *mlog.Log, dst, src string, srcReaderOpt io.Reader, sync bool) (rerr error) {
|
||||
func LinkOrCopy(log mlog.Log, dst, src string, srcReaderOpt io.Reader, sync bool) (rerr error) {
|
||||
// Try hardlink first.
|
||||
err := os.Link(src, dst)
|
||||
if err == nil {
|
||||
@ -48,7 +50,7 @@ func LinkOrCopy(log *mlog.Log, dst, src string, srcReaderOpt io.Reader, sync boo
|
||||
err := df.Close()
|
||||
log.Check(err, "closing partial destination file")
|
||||
err = os.Remove(dst)
|
||||
log.Check(err, "removing partial destination file", mlog.Field("path", dst))
|
||||
log.Check(err, "removing partial destination file", slog.String("path", dst))
|
||||
}
|
||||
}()
|
||||
|
||||
@ -64,7 +66,7 @@ func LinkOrCopy(log *mlog.Log, dst, src string, srcReaderOpt io.Reader, sync boo
|
||||
df = nil
|
||||
if err != nil {
|
||||
err := os.Remove(dst)
|
||||
log.Check(err, "removing partial destination file", mlog.Field("path", dst))
|
||||
log.Check(err, "removing partial destination file", slog.String("path", dst))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user