From cddd25e90896890df5baea77b3d93b7693f724a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=A0=E8=8F=B2?= Date: Thu, 19 Aug 2021 18:19:25 +0800 Subject: [PATCH] fix: adjust dfget download log (#564) * fix: adjust dfget download log Signed-off-by: zuozheng.hzz --- client/dfget/dfget.go | 8 ++++---- cmd/dfget/cmd/root.go | 13 +++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/client/dfget/dfget.go b/client/dfget/dfget.go index 01fd112ae4d..8c9df1c220a 100644 --- a/client/dfget/dfget.go +++ b/client/dfget/dfget.go @@ -107,8 +107,8 @@ func download(ctx context.Context, client daemonclient.DaemonClient, cfg *config _ = pb.Close() } - wLog.Infof("download from daemon success, length: %dByte cost: %dms", result.CompletedLength, time.Now().Sub(start).Milliseconds()) - fmt.Printf("finish total length %d Byte\n", result.CompletedLength) + wLog.Infof("download from daemon success, length: %d bytes cost: %d ms", result.CompletedLength, time.Now().Sub(start).Milliseconds()) + fmt.Printf("finish total length %d bytes\n", result.CompletedLength) break } @@ -174,8 +174,8 @@ func downloadFromSource(ctx context.Context, cfg *config.DfgetConfig, hdr map[st return err } - wLog.Infof("download from source success, length: %dByte cost: %dms", written, time.Now().Sub(start).Milliseconds()) - fmt.Printf("finish total length %d Byte\n", written) + wLog.Infof("download from source success, length: %d bytes cost: %d ms", written, time.Now().Sub(start).Milliseconds()) + fmt.Printf("finish total length %d bytes\n", written) return nil } diff --git a/cmd/dfget/cmd/root.go b/cmd/dfget/cmd/root.go index 3e96304b91e..cfaee67c959 100644 --- a/cmd/dfget/cmd/root.go +++ b/cmd/dfget/cmd/root.go @@ -82,17 +82,22 @@ var rootCmd = &cobra.Command{ } fmt.Printf("--%s-- %s\n", start.Format("2006-01-02 15:04:05"), dfgetConfig.URL) - fmt.Printf("current user[%s] output path[%s]\n", basic.Username, dfgetConfig.Output) - fmt.Printf("dfget version[%s] default peer ip[%s]\n", version.GitVersion, iputils.HostIP) + fmt.Printf("dfget version: %s\n", version.GitVersion) + fmt.Printf("current user: %s, default peer ip: %s\n", basic.Username, iputils.HostIP) + fmt.Printf("output path: %s\n", dfgetConfig.Output) // do get file + var errInfo string err := runDfget() + if err != nil { + errInfo = fmt.Sprintf("error: %v", err) + } - msg := fmt.Sprintf("download success: %t cost: %dms error:[%v]", err == nil, time.Now().Sub(start).Milliseconds(), err) + msg := fmt.Sprintf("download success: %t cost: %d ms %s", err == nil, time.Now().Sub(start).Milliseconds(), errInfo) logger.With("url", dfgetConfig.URL).Info(msg) fmt.Println(msg) - return errors.Wrapf(err, "download url[%s]", dfgetConfig.URL) + return errors.Wrapf(err, "download url: %s", dfgetConfig.URL) }, }