From 196729bae871342b4fd83704507996f5cb441a1b Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Thu, 29 Sep 2022 17:42:05 +0800 Subject: [PATCH] i18n: logs in conf/crontab/email/fs.driver --- pkg/conf/conf.go | 8 +++--- pkg/crontab/collect.go | 18 ++++++------- pkg/crontab/init.go | 6 ++--- pkg/email/init.go | 2 +- pkg/email/mail.go | 4 +-- pkg/email/smtp.go | 10 +++---- pkg/filesystem/driver/cos/handler.go | 2 +- pkg/filesystem/driver/local/handler.go | 32 +++++++++++------------ pkg/filesystem/driver/onedrive/api.go | 24 ++++++++--------- pkg/filesystem/driver/onedrive/client.go | 8 +++--- pkg/filesystem/driver/onedrive/handler.go | 2 +- pkg/filesystem/driver/onedrive/oauth.go | 2 +- pkg/filesystem/driver/oss/callback.go | 2 +- pkg/filesystem/driver/oss/handler.go | 6 ++--- pkg/filesystem/driver/remote/handler.go | 4 +-- pkg/filesystem/driver/s3/handler.go | 2 +- pkg/filesystem/driver/upyun/handler.go | 2 +- 17 files changed, 67 insertions(+), 67 deletions(-) diff --git a/pkg/conf/conf.go b/pkg/conf/conf.go index a9f7d06..c9e5c9a 100644 --- a/pkg/conf/conf.go +++ b/pkg/conf/conf.go @@ -85,13 +85,13 @@ func Init(path string) { }, defaultConf) f, err := util.CreatNestedFile(path) if err != nil { - util.Log().Panic("无法创建配置文件, %s", err) + util.Log().Panic("Failed to create config file: %s", err) } // 写入配置文件 _, err = f.WriteString(confContent) if err != nil { - util.Log().Panic("无法写入配置文件, %s", err) + util.Log().Panic("Failed to write config file: %s", err) } f.Close() @@ -99,7 +99,7 @@ func Init(path string) { cfg, err = ini.Load(path) if err != nil { - util.Log().Panic("无法解析配置文件 '%s': %s", path, err) + util.Log().Panic("Failed to parse config file %q: %s", path, err) } sections := map[string]interface{}{ @@ -114,7 +114,7 @@ func Init(path string) { for sectionName, sectionStruct := range sections { err = mapSection(sectionName, sectionStruct) if err != nil { - util.Log().Panic("配置文件 %s 分区解析失败: %s", sectionName, err) + util.Log().Panic("Failed to parse config section %q: %s", sectionName, err) } } diff --git a/pkg/crontab/collect.go b/pkg/crontab/collect.go index 79bf587..0667570 100644 --- a/pkg/crontab/collect.go +++ b/pkg/crontab/collect.go @@ -22,7 +22,7 @@ func garbageCollect() { collectCache(store) } - util.Log().Info("定时任务 [cron_garbage_collect] 执行完毕") + util.Log().Info("Crontab job \"cron_garbage_collect\" complete.") } func collectArchiveFile() { @@ -36,23 +36,23 @@ func collectArchiveFile() { if err == nil && !info.IsDir() && strings.HasPrefix(filepath.Base(path), "archive_") && time.Now().Sub(info.ModTime()).Seconds() > float64(expires) { - util.Log().Debug("删除过期打包下载临时文件 [%s]", path) + util.Log().Debug("Delete expired batch download temp file %q.", path) // 删除符合条件的文件 if err := os.Remove(path); err != nil { - util.Log().Debug("临时文件 [%s] 删除失败 , %s", path, err) + util.Log().Debug("Failed to delete temp file %q: %s", path, err) } } return nil }) if err != nil { - util.Log().Debug("[定时任务] 无法列取临时打包目录") + util.Log().Debug("Crontab job cannot list temp batch download folder: %s", err) } } func collectCache(store *cache.MemoStore) { - util.Log().Debug("清理内存缓存") + util.Log().Debug("Cleanup memory cache.") store.GarbageCollect() } @@ -78,22 +78,22 @@ func uploadSessionCollect() { for uid, filesIDs := range userToFiles { user, err := model.GetUserByID(uid) if err != nil { - util.Log().Warning("上传会话所属用户不存在, %s", err) + util.Log().Warning("Owner of the upload session cannot be found: %s", err) continue } fs, err := filesystem.NewFileSystem(&user) if err != nil { - util.Log().Warning("无法初始化文件系统, %s", err) + util.Log().Warning("Failed to initialize filesystem: %s", err) continue } if err = fs.Delete(context.Background(), []uint{}, filesIDs, false); err != nil { - util.Log().Warning("无法删除上传会话, %s", err) + util.Log().Warning("Failed to delete upload session: %s", err) } fs.Recycle() } - util.Log().Info("定时任务 [cron_recycle_upload_session] 执行完毕") + util.Log().Info("Crontab job \"cron_recycle_upload_session\" complete.") } diff --git a/pkg/crontab/init.go b/pkg/crontab/init.go index 0a696a4..5971c2c 100644 --- a/pkg/crontab/init.go +++ b/pkg/crontab/init.go @@ -19,7 +19,7 @@ func Reload() { // Init 初始化定时任务 func Init() { - util.Log().Info("初始化定时任务...") + util.Log().Info("Initialize crontab jobs...") // 读取cron日程设置 options := model.GetSettingByNames( "cron_garbage_collect", @@ -34,12 +34,12 @@ func Init() { case "cron_recycle_upload_session": handler = uploadSessionCollect default: - util.Log().Warning("未知定时任务类型 [%s],跳过", k) + util.Log().Warning("Unknown crontab job type %q, skipping...", k) continue } if _, err := Cron.AddFunc(v, handler); err != nil { - util.Log().Warning("无法启动定时任务 [%s] , %s", k, err) + util.Log().Warning("Failed to start crontab job %q: %s", k, err) } } diff --git a/pkg/email/init.go b/pkg/email/init.go index 64771a9..fe83fe3 100644 --- a/pkg/email/init.go +++ b/pkg/email/init.go @@ -15,7 +15,7 @@ var Lock sync.RWMutex // Init 初始化 func Init() { - util.Log().Debug("邮件队列初始化") + util.Log().Debug("Initializing email sending queue...") Lock.Lock() defer Lock.Unlock() diff --git a/pkg/email/mail.go b/pkg/email/mail.go index 01cc690..fbcbd68 100644 --- a/pkg/email/mail.go +++ b/pkg/email/mail.go @@ -15,9 +15,9 @@ type Driver interface { var ( // ErrChanNotOpen 邮件队列未开启 - ErrChanNotOpen = errors.New("邮件队列未开启") + ErrChanNotOpen = errors.New("email queue is not started") // ErrNoActiveDriver 无可用邮件发送服务 - ErrNoActiveDriver = errors.New("无可用邮件发送服务") + ErrNoActiveDriver = errors.New("no avaliable email provider") ) // Send 发送邮件 diff --git a/pkg/email/smtp.go b/pkg/email/smtp.go index 02376d7..c92cce7 100644 --- a/pkg/email/smtp.go +++ b/pkg/email/smtp.go @@ -68,7 +68,7 @@ func (client *SMTP) Init() { defer func() { if err := recover(); err != nil { client.chOpen = false - util.Log().Error("邮件发送队列出现异常, %s ,10 秒后重置", err) + util.Log().Error("Exception while sending email: %s, queue will be reset in 10 seconds.", err) time.Sleep(time.Duration(10) * time.Second) client.Init() } @@ -91,7 +91,7 @@ func (client *SMTP) Init() { select { case m, ok := <-client.ch: if !ok { - util.Log().Debug("邮件队列关闭") + util.Log().Debug("Email queue closing...") client.chOpen = false return } @@ -102,15 +102,15 @@ func (client *SMTP) Init() { open = true } if err := mail.Send(s, m); err != nil { - util.Log().Warning("邮件发送失败, %s", err) + util.Log().Warning("Failed to send email: %s", err) } else { - util.Log().Debug("邮件已发送") + util.Log().Debug("Email sent.") } // 长时间没有新邮件,则关闭SMTP连接 case <-time.After(time.Duration(client.Config.Keepalive) * time.Second): if open { if err := s.Close(); err != nil { - util.Log().Warning("无法关闭 SMTP 连接 %s", err) + util.Log().Warning("Failed to close SMTP connection: %s", err) } open = false } diff --git a/pkg/filesystem/driver/cos/handler.go b/pkg/filesystem/driver/cos/handler.go index 5389641..48ff09c 100644 --- a/pkg/filesystem/driver/cos/handler.go +++ b/pkg/filesystem/driver/cos/handler.go @@ -218,7 +218,7 @@ func (handler Driver) Delete(ctx context.Context, files []string) ([]string, err return failed, nil } - return failed, errors.New("删除失败") + return failed, errors.New("delete failed") } // Thumb 获取文件缩略图 diff --git a/pkg/filesystem/driver/local/handler.go b/pkg/filesystem/driver/local/handler.go index e5e8994..2c1205c 100644 --- a/pkg/filesystem/driver/local/handler.go +++ b/pkg/filesystem/driver/local/handler.go @@ -43,7 +43,7 @@ func (handler Driver) List(ctx context.Context, path string, recursive bool) ([] } if err != nil { - util.Log().Warning("无法遍历目录 %s, %s", path, err) + util.Log().Warning("Failed to walk folder %q: %s", path, err) return filepath.SkipDir } @@ -78,7 +78,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser, // 打开文件 file, err := os.Open(util.RelativePath(path)) if err != nil { - util.Log().Debug("无法打开文件:%s", err) + util.Log().Debug("Failed to open file: %s", err) return nil, err } @@ -94,8 +94,8 @@ func (handler Driver) Put(ctx context.Context, file fsctx.FileHeader) error { // 如果非 Overwrite,则检查是否有重名冲突 if fileInfo.Mode&fsctx.Overwrite != fsctx.Overwrite { if util.Exists(dst) { - util.Log().Warning("物理同名文件已存在或不可用: %s", dst) - return errors.New("物理同名文件已存在或不可用") + util.Log().Warning("File with the same name existed or unavailable: %s", dst) + return errors.New("file with the same name existed or unavailable") } } @@ -104,7 +104,7 @@ func (handler Driver) Put(ctx context.Context, file fsctx.FileHeader) error { if !util.Exists(basePath) { err := os.MkdirAll(basePath, Perm) if err != nil { - util.Log().Warning("无法创建目录,%s", err) + util.Log().Warning("Failed to create directory: %s", err) return err } } @@ -123,7 +123,7 @@ func (handler Driver) Put(ctx context.Context, file fsctx.FileHeader) error { out, err = os.OpenFile(dst, openMode, Perm) if err != nil { - util.Log().Warning("无法打开或创建文件,%s", err) + util.Log().Warning("Failed to open or create file: %s", err) return err } defer out.Close() @@ -131,22 +131,22 @@ func (handler Driver) Put(ctx context.Context, file fsctx.FileHeader) error { if fileInfo.Mode&fsctx.Append == fsctx.Append { stat, err := out.Stat() if err != nil { - util.Log().Warning("无法读取文件信息,%s", err) + util.Log().Warning("Failed to read file info: %s", err) return err } if uint64(stat.Size()) < fileInfo.AppendStart { - return errors.New("未上传完成的文件分片与预期大小不一致") + return errors.New("size of unfinished uploaded chunks is not as expected") } else if uint64(stat.Size()) > fileInfo.AppendStart { out.Close() if err := handler.Truncate(ctx, dst, fileInfo.AppendStart); err != nil { - return fmt.Errorf("覆盖分片时发生错误: %w", err) + return fmt.Errorf("failed to overwrite chunk: %w", err) } out, err = os.OpenFile(dst, openMode, Perm) defer out.Close() if err != nil { - util.Log().Warning("无法打开或创建文件,%s", err) + util.Log().Warning("Failed to create or open file: %s", err) return err } } @@ -158,10 +158,10 @@ func (handler Driver) Put(ctx context.Context, file fsctx.FileHeader) error { } func (handler Driver) Truncate(ctx context.Context, src string, size uint64) error { - util.Log().Warning("截断文件 [%s] 至 [%d]", src, size) + util.Log().Warning("Truncate file %q to [%d].", src, size) out, err := os.OpenFile(src, os.O_WRONLY, Perm) if err != nil { - util.Log().Warning("无法打开文件,%s", err) + util.Log().Warning("Failed to open file: %s", err) return err } @@ -180,7 +180,7 @@ func (handler Driver) Delete(ctx context.Context, files []string) ([]string, err if util.Exists(filePath) { err := os.Remove(filePath) if err != nil { - util.Log().Warning("无法删除文件,%s", err) + util.Log().Warning("Failed to delete file: %s", err) retErr = err deleteFailed = append(deleteFailed, value) } @@ -217,7 +217,7 @@ func (handler Driver) Source( ) (string, error) { file, ok := ctx.Value(fsctx.FileModelCtx).(model.File) if !ok { - return "", errors.New("无法获取文件记录上下文") + return "", errors.New("failed to read file model context") } // 是否启用了CDN @@ -238,7 +238,7 @@ func (handler Driver) Source( downloadSessionID := util.RandStringRunes(16) err = cache.Set("download_"+downloadSessionID, file, int(ttl)) if err != nil { - return "", serializer.NewError(serializer.CodeCacheOperation, "无法创建下载会话", err) + return "", serializer.NewError(serializer.CodeCacheOperation, "Failed to create download session", err) } // 签名生成文件记录 @@ -257,7 +257,7 @@ func (handler Driver) Source( } if err != nil { - return "", serializer.NewError(serializer.CodeEncryptError, "无法对URL进行签名", err) + return "", serializer.NewError(serializer.CodeEncryptError, "Failed to sign url", err) } finalURL := baseURL.ResolveReference(signedURI).String() diff --git a/pkg/filesystem/driver/onedrive/api.go b/pkg/filesystem/driver/onedrive/api.go index 438459a..1e41b72 100644 --- a/pkg/filesystem/driver/onedrive/api.go +++ b/pkg/filesystem/driver/onedrive/api.go @@ -95,7 +95,7 @@ func (client *Client) ListChildren(ctx context.Context, path string) ([]FileInfo } if retried < ListRetry { retried++ - util.Log().Debug("路径[%s]列取请求失败[%s],5秒钟后重试", path, err) + util.Log().Debug("Failed to list path %q: %s, will retry in 5 seconds.", path, err) time.Sleep(time.Duration(5) * time.Second) return client.ListChildren(context.WithValue(ctx, fsctx.RetryCtx, retried), path) } @@ -445,7 +445,7 @@ func (client *Client) GetThumbURL(ctx context.Context, dst string, w, h uint) (s } } - return "", errors.New("无法生成缩略图") + return "", errors.New("failed to generate thumb") } // MonitorUpload 监控客户端分片上传进度 @@ -460,39 +460,39 @@ func (client *Client) MonitorUpload(uploadURL, callbackKey, path string, size ui for { select { case <-callbackChan: - util.Log().Debug("客户端完成回调") + util.Log().Debug("Client finished OneDrive callback.") return case <-time.After(time.Duration(ttl) * time.Second): // 上传会话到期,仍未完成上传,创建占位符 client.DeleteUploadSession(context.Background(), uploadURL) _, err := client.SimpleUpload(context.Background(), path, strings.NewReader(""), 0, WithConflictBehavior("replace")) if err != nil { - util.Log().Debug("无法创建占位文件,%s", err) + util.Log().Debug("Failed to create placeholder file: %s", err) } return case <-time.After(time.Duration(timeout) * time.Second): - util.Log().Debug("检查上传情况") + util.Log().Debug("Checking OneDrive upload status.") status, err := client.GetUploadSessionStatus(context.Background(), uploadURL) if err != nil { if resErr, ok := err.(*RespError); ok { if resErr.APIError.Code == "itemNotFound" { - util.Log().Debug("上传会话已完成,稍后检查回调") + util.Log().Debug("Upload completed, will check upload callback later.") select { case <-time.After(time.Duration(interval) * time.Second): - util.Log().Warning("未发送回调,删除文件") + util.Log().Warning("No callback is made, file will be deleted.") cache.Deletes([]string{callbackKey}, "callback_") _, err = client.Delete(context.Background(), []string{path}) if err != nil { - util.Log().Warning("无法删除未回调的文件,%s", err) + util.Log().Warning("Failed to delete file without callback: %s", err) } case <-callbackChan: - util.Log().Debug("客户端完成回调") + util.Log().Debug("Client finished callback.") } return } } - util.Log().Debug("无法获取上传会话状态,继续下一轮,%s", err.Error()) + util.Log().Debug("Failed to get upload session status: %s, continue next iteration.", err.Error()) continue } @@ -509,7 +509,7 @@ func (client *Client) MonitorUpload(uploadURL, callbackKey, path string, size ui } uploadFullSize, _ := strconv.ParseUint(sizeRange[1], 10, 64) if (sizeRange[0] == "0" && sizeRange[1] == "") || uploadFullSize+1 != size { - util.Log().Debug("未开始上传或文件大小不一致,取消上传会话") + util.Log().Debug("Upload has not started, or uploaded file size not match, canceling upload session...") // 取消上传会话,实测OneDrive取消上传会话后,客户端还是可以上传, // 所以上传一个空文件占位,阻止客户端上传 client.DeleteUploadSession(context.Background(), uploadURL) @@ -577,7 +577,7 @@ func (client *Client) request(ctx context.Context, method string, url string, bo if res.Response.StatusCode < 200 || res.Response.StatusCode >= 300 { decodeErr = json.Unmarshal([]byte(respBody), &errResp) if decodeErr != nil { - util.Log().Debug("Onedrive返回未知响应[%s]", respBody) + util.Log().Debug("Onedrive returns unknown response: %s", respBody) return "", sysError(decodeErr) } return "", &errResp diff --git a/pkg/filesystem/driver/onedrive/client.go b/pkg/filesystem/driver/onedrive/client.go index dfd205c..149fcf0 100644 --- a/pkg/filesystem/driver/onedrive/client.go +++ b/pkg/filesystem/driver/onedrive/client.go @@ -10,13 +10,13 @@ import ( var ( // ErrAuthEndpoint 无法解析授权端点地址 - ErrAuthEndpoint = errors.New("无法解析授权端点地址") + ErrAuthEndpoint = errors.New("failed to parse endpoint url") // ErrInvalidRefreshToken 上传策略无有效的RefreshToken - ErrInvalidRefreshToken = errors.New("上传策略无有效的RefreshToken") + ErrInvalidRefreshToken = errors.New("no valid refresh token in this policy") // ErrDeleteFile 无法删除文件 - ErrDeleteFile = errors.New("无法删除文件") + ErrDeleteFile = errors.New("cannot delete file") // ErrClientCanceled 客户端取消操作 - ErrClientCanceled = errors.New("客户端取消操作") + ErrClientCanceled = errors.New("client canceled") ) // Client OneDrive客户端 diff --git a/pkg/filesystem/driver/onedrive/handler.go b/pkg/filesystem/driver/onedrive/handler.go index 8eec3b3..98b2ba7 100644 --- a/pkg/filesystem/driver/onedrive/handler.go +++ b/pkg/filesystem/driver/onedrive/handler.go @@ -143,7 +143,7 @@ func (handler Driver) Thumb(ctx context.Context, path string) (*response.Content ok = false ) if thumbSize, ok = ctx.Value(fsctx.ThumbSizeCtx).([2]uint); !ok { - return nil, errors.New("无法获取缩略图尺寸设置") + return nil, errors.New("failed to get thumbnail size") } res, err := handler.Client.GetThumbURL(ctx, path, thumbSize[0], thumbSize[1]) diff --git a/pkg/filesystem/driver/onedrive/oauth.go b/pkg/filesystem/driver/onedrive/oauth.go index d7edbb5..914a498 100644 --- a/pkg/filesystem/driver/onedrive/oauth.go +++ b/pkg/filesystem/driver/onedrive/oauth.go @@ -152,7 +152,7 @@ func (client *Client) UpdateCredential(ctx context.Context, isSlave bool) error // 获取新的凭证 if client.Credential == nil || client.Credential.RefreshToken == "" { // 无有效的RefreshToken - util.Log().Error("上传策略[%s]凭证刷新失败,请重新授权OneDrive账号", client.Policy.Name) + util.Log().Error("Failed to refresh credential for policy %q, please login your Microsoft account again.", client.Policy.Name) return ErrInvalidRefreshToken } diff --git a/pkg/filesystem/driver/oss/callback.go b/pkg/filesystem/driver/oss/callback.go index e5b41bb..b2a8803 100644 --- a/pkg/filesystem/driver/oss/callback.go +++ b/pkg/filesystem/driver/oss/callback.go @@ -38,7 +38,7 @@ func GetPublicKey(r *http.Request) ([]byte, error) { // 确保这个 public key 是由 OSS 颁发的 if !strings.HasPrefix(string(pubURL), "http://gosspublic.alicdn.com/") && !strings.HasPrefix(string(pubURL), "https://gosspublic.alicdn.com/") { - return pubKey, errors.New("公钥URL无效") + return pubKey, errors.New("public key url invalid") } // 获取公钥 diff --git a/pkg/filesystem/driver/oss/handler.go b/pkg/filesystem/driver/oss/handler.go index 62bccbc..af27816 100644 --- a/pkg/filesystem/driver/oss/handler.go +++ b/pkg/filesystem/driver/oss/handler.go @@ -91,7 +91,7 @@ func (handler *Driver) CORS() error { // InitOSSClient 初始化OSS鉴权客户端 func (handler *Driver) InitOSSClient(forceUsePublicEndpoint bool) error { if handler.Policy == nil { - return errors.New("存储策略为空") + return errors.New("empty policy") } // 决定是否使用内网 Endpoint @@ -286,7 +286,7 @@ func (handler *Driver) Delete(ctx context.Context, files []string) ([]string, er // 统计未删除的文件 failed := util.SliceDifference(files, delRes.DeletedObjects) if len(failed) > 0 { - return failed, errors.New("删除失败") + return failed, errors.New("failed to delete") } return []string{}, nil @@ -304,7 +304,7 @@ func (handler *Driver) Thumb(ctx context.Context, path string) (*response.Conten ok = false ) if thumbSize, ok = ctx.Value(fsctx.ThumbSizeCtx).([2]uint); !ok { - return nil, errors.New("无法获取缩略图尺寸设置") + return nil, errors.New("failed to get thumbnail size") } thumbParam := fmt.Sprintf("image/resize,m_lfit,h_%d,w_%d", thumbSize[1], thumbSize[0]) diff --git a/pkg/filesystem/driver/remote/handler.go b/pkg/filesystem/driver/remote/handler.go index 7594753..9b88e8d 100644 --- a/pkg/filesystem/driver/remote/handler.go +++ b/pkg/filesystem/driver/remote/handler.go @@ -197,7 +197,7 @@ func (handler *Driver) Delete(ctx context.Context, files []string) ([]string, er return failedResp.Files, errors.New(reqResp.Error) } } - return files, errors.New("未知的返回结果格式") + return files, errors.New("unknown format of returned response") } return []string{}, nil @@ -265,7 +265,7 @@ func (handler *Driver) Source( ) if err != nil { - return "", serializer.NewError(serializer.CodeEncryptError, "无法对URL进行签名", err) + return "", serializer.NewError(serializer.CodeEncryptError, "Failed to sign URL", err) } finalURL := serverURL.ResolveReference(signedURI).String() diff --git a/pkg/filesystem/driver/s3/handler.go b/pkg/filesystem/driver/s3/handler.go index fe6007a..a6d17bf 100644 --- a/pkg/filesystem/driver/s3/handler.go +++ b/pkg/filesystem/driver/s3/handler.go @@ -62,7 +62,7 @@ func NewDriver(policy *model.Policy) (*Driver, error) { // InitS3Client 初始化S3会话 func (handler *Driver) InitS3Client() error { if handler.Policy == nil { - return errors.New("存储策略为空") + return errors.New("empty policy") } if handler.svc == nil { diff --git a/pkg/filesystem/driver/upyun/handler.go b/pkg/filesystem/driver/upyun/handler.go index 0357f72..8fed080 100644 --- a/pkg/filesystem/driver/upyun/handler.go +++ b/pkg/filesystem/driver/upyun/handler.go @@ -226,7 +226,7 @@ func (handler Driver) Thumb(ctx context.Context, path string) (*response.Content ok = false ) if thumbSize, ok = ctx.Value(fsctx.ThumbSizeCtx).([2]uint); !ok { - return nil, errors.New("无法获取缩略图尺寸设置") + return nil, errors.New("failed to get thumbnail size") } thumbParam := fmt.Sprintf("!/fwfh/%dx%d", thumbSize[0], thumbSize[1])