refactor: replace logger usage with common.Log for consistent logging

This commit is contained in:
krau
2025-03-21 21:07:53 +08:00
parent 65fee89e14
commit ed0837a89b
27 changed files with 152 additions and 158 deletions

View File

@@ -6,7 +6,7 @@ import (
"io"
"path"
"github.com/krau/SaveAny-Bot/logger"
"github.com/krau/SaveAny-Bot/common"
)
type WebdavWriter struct {
@@ -32,7 +32,7 @@ func (w *WebdavWriter) Close() error {
func (w *Webdav) NewUploadStream(ctx context.Context, storagePath string) (io.WriteCloser, error) {
if err := w.client.MkDir(ctx, path.Dir(storagePath)); err != nil {
logger.L.Errorf("Failed to create directory %s: %v", path.Dir(storagePath), err)
common.Log.Errorf("Failed to create directory %s: %v", path.Dir(storagePath), err)
return nil, ErrFailedToCreateDirectory
}
pipeReader, pipeWriter := io.Pipe()

View File

@@ -8,8 +8,8 @@ import (
"path"
"time"
"github.com/krau/SaveAny-Bot/common"
config "github.com/krau/SaveAny-Bot/config/storage"
"github.com/krau/SaveAny-Bot/logger"
"github.com/krau/SaveAny-Bot/types"
)
@@ -42,20 +42,20 @@ func (w *Webdav) Name() string {
}
func (w *Webdav) Save(ctx context.Context, filePath, storagePath string) error {
logger.L.Infof("Saving file %s to %s", filePath, storagePath)
common.Log.Infof("Saving file %s to %s", filePath, storagePath)
if err := w.client.MkDir(ctx, path.Dir(storagePath)); err != nil {
logger.L.Errorf("Failed to create directory %s: %v", path.Dir(storagePath), err)
common.Log.Errorf("Failed to create directory %s: %v", path.Dir(storagePath), err)
return ErrFailedToCreateDirectory
}
file, err := os.Open(filePath)
if err != nil {
logger.L.Errorf("Failed to open file %s: %v", filePath, err)
common.Log.Errorf("Failed to open file %s: %v", filePath, err)
return err
}
defer file.Close()
if err := w.client.WriteFile(ctx, storagePath, file); err != nil {
logger.L.Errorf("Failed to write file %s: %v", storagePath, err)
common.Log.Errorf("Failed to write file %s: %v", storagePath, err)
return ErrFailedToWriteFile
}
return nil