Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add zap log print #233

Open
wants to merge 1 commit into
base: tombstone
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Feat: add zap log print
Signed-off-by: fengshunli <1171313930@qq.com>
fengshunli committed May 22, 2023
commit 7944dafd6faaed06b0d1e3098d86396e8386a831
51 changes: 24 additions & 27 deletions cli/cli/cli.go
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ package cli
import (
"errors"
"fmt"
"go.uber.org/zap"
"io"
"os"
"path"
@@ -41,7 +42,7 @@ import (
tui "github.com/opencurve/curveadm/internal/tui/common"
"github.com/opencurve/curveadm/internal/utils"
cliutil "github.com/opencurve/curveadm/internal/utils"
log "github.com/opencurve/curveadm/pkg/log/glg"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"github.com/opencurve/curveadm/pkg/module"
)

@@ -131,15 +132,11 @@ func (curveadm *CurveAdm) init() error {
configure.ReplaceGlobals(config)

// (3) Init logger
now := time.Now().Format("2006-01-02_15-04-05")
logpath := fmt.Sprintf("%s/curveadm-%s.log", curveadm.logDir, now)
if err := log.Init(config.GetLogLevel(), logpath); err != nil {
return errno.ERR_INIT_LOGGER_FAILED.E(err)
} else {
log.Info("Init logger success",
log.Field("LogPath", logpath),
log.Field("LogLevel", config.GetLogLevel()))
}
logpath := fmt.Sprintf("%s/curveadm.log", curveadm.logDir)
zaplog.Init(config, logpath)

zaplog.Info("Init logger success",
zap.String("LogPath", logpath))

// (4) Init error code
errno.Init(logpath)
@@ -148,17 +145,17 @@ func (curveadm *CurveAdm) init() error {
dbpath := fmt.Sprintf("%s/curveadm.db", curveadm.dataDir)
s, err := storage.NewStorage(dbpath)
if err != nil {
log.Error("Init SQLite database failed",
log.Field("Error", err))
zaplog.Error("Init SQLite database failed",
zap.Any("Error", err))
return errno.ERR_INIT_SQL_DATABASE_FAILED.E(err)
}

// (6) Get hosts
var hosts storage.Hosts
hostses, err := s.GetHostses()
if err != nil {
log.Error("Get hosts failed",
log.Field("Error", err))
zaplog.Error("Get hosts failed",
zap.Any("Error", err))
return errno.ERR_GET_HOSTS_FAILED.E(err)
} else if len(hostses) == 1 {
hosts = hostses[0]
@@ -167,20 +164,20 @@ func (curveadm *CurveAdm) init() error {
// (7) Get current cluster
cluster, err := s.GetCurrentCluster()
if err != nil {
log.Error("Get current cluster failed",
log.Field("Error", err))
zaplog.Error("Get current cluster failed",
zap.Any("Error", err))
return errno.ERR_GET_CURRENT_CLUSTER_FAILED.E(err)
} else {
log.Info("Get current cluster success",
log.Field("ClusterId", cluster.Id),
log.Field("ClusterName", cluster.Name))
zaplog.Info("Get current cluster success",
zap.Int("ClusterId", cluster.Id),
zap.String("ClusterName", cluster.Name))
}

// (8) Get Disks
var disks storage.Disks
diskses, err := s.GetDisks()
if err != nil {
log.Error("Get disks failed", log.Field("Error", err))
zaplog.Error("Get disks failed", zap.Any("Error", err))
return errno.ERR_GET_DISKS_FAILED.E(err)
} else if len(diskses) > 0 {
disks = diskses[0]
@@ -189,7 +186,7 @@ func (curveadm *CurveAdm) init() error {
// (9) Get Disk Records
diskRecords, err := s.GetDisk(comm.DISK_FILTER_ALL)
if err != nil {
log.Error("Get disk records failed", log.Field("Error", err))
zaplog.Error("Get disk records failed", zap.Any("Error", err))
return errno.ERR_GET_DISK_RECORDS_FAILED.E(err)
}

@@ -507,8 +504,8 @@ func (curveadm *CurveAdm) PreAudit(now time.Time, args []string) int64 {
id, err := curveadm.Storage().InsertAuditLog(
now, cwd, command, comm.AUDIT_STATUS_ABORT)
if err != nil {
log.Error("Insert audit log failed",
log.Field("Error", err))
zaplog.Error("Insert audit log failed",
zap.Any("Error", err))
}

return id
@@ -521,8 +518,8 @@ func (curveadm *CurveAdm) PostAudit(id int64, ec error) {

auditLogs, err := curveadm.Storage().GetAuditLog(id)
if err != nil {
log.Error("Get audit log failed",
log.Field("Error", err))
zaplog.Error("Get audit log failed",
zap.Any("Error", err))
return
} else if len(auditLogs) != 1 {
return
@@ -544,7 +541,7 @@ func (curveadm *CurveAdm) PostAudit(id int64, ec error) {

err = curveadm.Storage().SetAuditLogStatus(id, status, errorCode)
if err != nil {
log.Error("Set audit log status failed",
log.Field("Error", err))
zaplog.Error("Set audit log status failed",
zap.Any("Error", err))
}
}
9 changes: 5 additions & 4 deletions cli/command/cluster/add.go
Original file line number Diff line number Diff line change
@@ -31,8 +31,9 @@ import (
"github.com/opencurve/curveadm/internal/errno"
"github.com/opencurve/curveadm/internal/playbook"
"github.com/opencurve/curveadm/internal/utils"
log "github.com/opencurve/curveadm/pkg/log/glg"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

const (
@@ -139,9 +140,9 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
storage := curveadm.Storage()
clusters, err := storage.GetClusters(name)
if err != nil {
log.Error("Get clusters failed",
log.Field("cluster name", name),
log.Field("error", err))
zaplog.Error("Get clusters failed",
zap.String("cluster name", name),
zap.Any("error", err))
return errno.ERR_GET_ALL_CLUSTERS_FAILED.E(err)
} else if len(clusters) > 0 {
return errno.ERR_CLUSTER_ALREADY_EXIST.
7 changes: 4 additions & 3 deletions cli/command/cluster/checkout.go
Original file line number Diff line number Diff line change
@@ -28,8 +28,9 @@ import (
"github.com/opencurve/curveadm/cli/cli"
"github.com/opencurve/curveadm/internal/errno"
cliutil "github.com/opencurve/curveadm/internal/utils"
log "github.com/opencurve/curveadm/pkg/log/glg"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

type checkoutOptions struct {
@@ -59,8 +60,8 @@ func runCheckout(curveadm *cli.CurveAdm, options checkoutOptions) error {
storage := curveadm.Storage()
clusters, err := storage.GetClusters(clusterName)
if err != nil {
log.Error("Get clusters failed",
log.Field("error", err))
zaplog.Error("Get clusters failed",
zap.Any("error", err))
return errno.ERR_GET_ALL_CLUSTERS_FAILED.E(err)
} else if len(clusters) == 0 {
return errno.ERR_CLUSTER_NOT_FOUND.
7 changes: 4 additions & 3 deletions cli/command/cluster/export.go
Original file line number Diff line number Diff line change
@@ -24,12 +24,13 @@ package cluster

import (
"fmt"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"go.uber.org/zap"
"os"

"github.com/opencurve/curveadm/cli/cli"
"github.com/opencurve/curveadm/internal/storage"
"github.com/opencurve/curveadm/internal/utils"
log "github.com/opencurve/curveadm/pkg/log/glg"
"github.com/spf13/cobra"
)

@@ -129,12 +130,12 @@ func runExport(curveadm *cli.CurveAdm, options exportOptions) error {
storage := curveadm.Storage()
clusters, err := storage.GetClusters(name)
if err != nil {
log.Error("GetClusters", log.Field("error", err))
zaplog.Error("GetClusters", zap.Any("error", err))
return err
} else if len(clusters) == 0 {
return fmt.Errorf("cluster %s not exist", name)
} else if services, err := storage.GetServices(clusters[0].Id); err != nil {
log.Error("GetServices", log.Field("error", err))
zaplog.Error("GetServices", zap.Any("error", err))
return err
} else if err = exportCluster(clusters[0], services, options.outfile); err != nil {
return err
5 changes: 3 additions & 2 deletions cli/command/cluster/import.go
Original file line number Diff line number Diff line change
@@ -24,13 +24,14 @@ package cluster

import (
"fmt"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"go.uber.org/zap"
"io"
"os"
"regexp"
"strconv"
"strings"

"github.com/opencurve/curveadm/pkg/log/zaplog"
"github.com/opencurve/curveadm/cli/cli"
"github.com/opencurve/curveadm/internal/storage"
"github.com/opencurve/curveadm/internal/utils"
@@ -189,7 +190,7 @@ func runImport(curveadm *cli.CurveAdm, options importOptions) error {
storage := curveadm.Storage()
clusters, err := storage.GetClusters(name)
if err != nil {
zaplog.Error("GetClusters", zaplog.Field("error", err))
zaplog.Error("GetClusters", zap.Any("error", err))
return err
} else if len(clusters) != 0 {
return fmt.Errorf("cluster %s already exist", name)
7 changes: 4 additions & 3 deletions cli/command/cluster/list.go
Original file line number Diff line number Diff line change
@@ -29,8 +29,9 @@ import (
"github.com/opencurve/curveadm/internal/errno"
"github.com/opencurve/curveadm/internal/tui"
cliutil "github.com/opencurve/curveadm/internal/utils"
log "github.com/opencurve/curveadm/pkg/log/glg"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

type listOptions struct {
@@ -62,8 +63,8 @@ func runList(curveadm *cli.CurveAdm, options listOptions) error {
storage := curveadm.Storage()
clusters, err := storage.GetClusters("%")
if err != nil {
log.Error("Get clusters failed",
log.Field("error", err))
zaplog.Error("Get clusters failed",
zap.Any("error", err))
return errno.ERR_GET_ALL_CLUSTERS_FAILED.E(err)
}

7 changes: 4 additions & 3 deletions cli/command/cluster/remove.go
Original file line number Diff line number Diff line change
@@ -30,8 +30,9 @@ import (
"github.com/opencurve/curveadm/internal/errno"
tui "github.com/opencurve/curveadm/internal/tui/common"
cliutil "github.com/opencurve/curveadm/internal/utils"
log "github.com/opencurve/curveadm/pkg/log/glg"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

type removeOptions struct {
@@ -86,8 +87,8 @@ func runRemove(curveadm *cli.CurveAdm, options removeOptions) error {
clusterName := options.clusterName
clusters, err := storage.GetClusters(clusterName) // Get all clusters
if err != nil {
log.Error("Get cluster failed",
log.Field("error", err))
zaplog.Error("Get cluster failed",
zap.Any("error", err))
return errno.ERR_GET_ALL_CLUSTERS_FAILED.E(err)
} else if len(clusters) == 0 {
return errno.ERR_CLUSTER_NOT_FOUND.
5 changes: 3 additions & 2 deletions internal/configure/client.go
Original file line number Diff line number Diff line change
@@ -25,13 +25,14 @@ package configure
import (
"bytes"
"fmt"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"go.uber.org/zap"
"strings"

"github.com/opencurve/curveadm/internal/build"
"github.com/opencurve/curveadm/internal/configure/topology"
"github.com/opencurve/curveadm/internal/errno"
"github.com/opencurve/curveadm/internal/utils"
log "github.com/opencurve/curveadm/pkg/log/glg"
"github.com/opencurve/curveadm/pkg/variable"
"github.com/spf13/viper"
)
@@ -104,7 +105,7 @@ func NewClientConfig(config map[string]interface{}) (*ClientConfig, error) {
vars.Register(variable.Variable{Name: "prefix", Value: "/curvebs/nebd"})
err := vars.Build()
if err != nil {
log.Error("Build variables failed", log.Field("Error", err))
zaplog.Error("Build variables failed", zap.Any("Error", err))
return nil, errno.ERR_RESOLVE_CLIENT_VARIABLE_FAILED.E(err)
}

28 changes: 16 additions & 12 deletions internal/configure/curveadm/curveadm.go
Original file line number Diff line number Diff line change
@@ -54,12 +54,14 @@ const (

type (
CurveAdmConfig struct {
LogLevel string
SudoAlias string
Timeout int
AutoUpgrade bool
SSHRetries int
SSHTimeout int
LogLevel string
SudoAlias string
Timeout int
AutoUpgrade bool
ShowLine bool
LogInConsole bool
SSHRetries int
SSHTimeout int
}

CurveAdm struct {
@@ -72,12 +74,14 @@ var (
GlobalCurveAdmConfig *CurveAdmConfig

defaultCurveAdmConfig = &CurveAdmConfig{
LogLevel: "error",
SudoAlias: "sudo",
Timeout: 180,
AutoUpgrade: true,
SSHRetries: 3,
SSHTimeout: 10,
LogLevel: "info",
SudoAlias: "sudo",
Timeout: 180,
AutoUpgrade: true,
ShowLine: true,
LogInConsole: true,
SSHRetries: 3,
SSHTimeout: 10,
}

SUPPORT_LOG_LEVEL = map[string]bool{
11 changes: 6 additions & 5 deletions internal/configure/topology/dc.go
Original file line number Diff line number Diff line change
@@ -26,12 +26,13 @@ package topology

import (
"fmt"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"go.uber.org/zap"
"strconv"

"github.com/opencurve/curveadm/internal/build"
"github.com/opencurve/curveadm/internal/errno"
"github.com/opencurve/curveadm/internal/utils"
log "github.com/opencurve/curveadm/pkg/log/glg"
"github.com/opencurve/curveadm/pkg/variable"
)

@@ -156,8 +157,8 @@ func NewDeployConfig(ctx *Context, kind, role, host, name string, replicas int,
func (dc *DeployConfig) renderVariables() error {
vars := dc.GetVariables()
if err := vars.Build(); err != nil {
log.Error("Build variables failed",
log.Field("error", err))
zaplog.Error("Build variables failed",
zap.Any("error", err))
return errno.ERR_RESOLVE_VARIABLE_FAILED.E(err)
}

@@ -257,8 +258,8 @@ func (dc *DeployConfig) ResolveHost() error {

vars := dc.GetVariables()
if err := vars.Build(); err != nil {
log.Error("Build variables failed",
log.Field("error", err))
zaplog.Error("Build variables failed",
zap.Any("error", err))
return errno.ERR_RESOLVE_VARIABLE_FAILED.E(err)
}

9 changes: 5 additions & 4 deletions internal/task/task/common/create_container.go
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@ package common

import (
"fmt"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"go.uber.org/zap"
"strings"

"github.com/opencurve/curveadm/cli/cli"
@@ -37,7 +39,6 @@ import (
"github.com/opencurve/curveadm/internal/task/context"
"github.com/opencurve/curveadm/internal/task/step"
"github.com/opencurve/curveadm/internal/task/task"
log "github.com/opencurve/curveadm/pkg/log/glg"
)

type step2GetService struct {
@@ -90,9 +91,9 @@ func (s *step2InsertService) Execute(ctx *context.Context) error {
err = s.E(err, errno.ERR_INSERT_SERVICE_CONTAINER_ID_FAILED)
}

log.SwitchLevel(err)("Insert service",
log.Field("ServiceId", serviceId),
log.Field("ContainerId", containerId))
zaplog.Error("Insert service",
zap.String("ServiceId", serviceId),
zap.String("ContainerId", containerId))

return err
}
1 change: 0 additions & 1 deletion pkg/log/glg/glg.go

This file was deleted.

117 changes: 0 additions & 117 deletions pkg/log/glg/log.go

This file was deleted.

77 changes: 0 additions & 77 deletions pkg/log/log.go

This file was deleted.

135 changes: 100 additions & 35 deletions pkg/log/zaplog/log.go
Original file line number Diff line number Diff line change
@@ -25,55 +25,120 @@
package zaplog

import (
zaplog "github.com/pingcap/log"
"github.com/opencurve/curveadm/internal/configure/curveadm"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
"os"
"time"
)

var (
Debug = zaplog.Debug
Info = zaplog.Info
Warn = zaplog.Warn
Error = zaplog.Error
level zapcore.Level
logger *zap.Logger
cfg *curveadm.CurveAdmConfig
logpath string
LOG *zap.Logger
)

func Init(level, filename string) error {
gl, props, err := zaplog.InitLogger(&zaplog.Config{
Level: level,
File: zaplog.FileLogConfig{Filename: filename},
Format: "text",
DisableTimestamp: false,
}, zap.AddStacktrace(zapcore.FatalLevel))
func Init(config *curveadm.CurveAdmConfig, path string) {
cfg = config
logpath = path
logger = Zap()
}
func Zap() (logger *zap.Logger) {
switch cfg.GetLogLevel() {
case "debug":
level = zap.DebugLevel
case "info":
level = zap.InfoLevel
case "warn":
level = zap.WarnLevel
case "error":
level = zap.ErrorLevel
case "dpanic":
level = zap.DPanicLevel
case "panic":
level = zap.PanicLevel
case "fatal":
level = zap.FatalLevel
default:
level = zap.InfoLevel
}

if err != nil {
return err
if level == zap.ErrorLevel {
logger = zap.New(getEncoderCore(), zap.AddStacktrace(level))
} else {
logger = zap.New(getEncoderCore())
}

zaplog.ReplaceGlobals(gl, props)
return nil
if cfg.ShowLine {
logger = logger.WithOptions(zap.AddCaller())
}
return logger
}

func SwitchLevel(err error) func(msg string, fields ...zap.Field) {
if err != nil {
return zaplog.Error
func getEncoderConfig() (config zapcore.EncoderConfig) {
config = zapcore.EncoderConfig{
MessageKey: "message",
LevelKey: "level",
TimeKey: "time",
NameKey: "logger",
CallerKey: "caller",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeTime: CustomTimeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.FullCallerEncoder,
}

switch "LowercaseLevelEncoder" {
case "LowercaseLevelEncoder":
config.EncodeLevel = zapcore.LowercaseLevelEncoder
case "LowercaseColorLevelEncoder":
config.EncodeLevel = zapcore.LowercaseColorLevelEncoder
case "CapitalLevelEncoder":
config.EncodeLevel = zapcore.CapitalLevelEncoder
case "CapitalColorLevelEncoder":
config.EncodeLevel = zapcore.CapitalColorLevelEncoder
default:
config.EncodeLevel = zapcore.LowercaseLevelEncoder
}
return zaplog.Info
return config
}

func getEncoder() zapcore.Encoder {
return zapcore.NewConsoleEncoder(getEncoderConfig())
}

func getEncoderCore() (core zapcore.Core) {
writer := getWriteSyncer()
return zapcore.NewCore(getEncoder(), writer, level)
}

func Field(key string, val interface{}) zap.Field {
switch val.(type) {
case bool:
return zap.Bool(key, val.(bool))
case string:
return zap.String(key, val.(string))
case []byte:
return zap.String(key, string(val.([]byte)))
case int:
return zap.Int(key, val.(int))
case int64:
return zap.Int64(key, val.(int64))
case error:
return zap.String(key, val.(error).Error())
func CustomTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format("curveadm" + " 2006/01/02 15:04:05"))
}

func getWriteSyncer() zapcore.WriteSyncer {
lumberJackLogger := &lumberjack.Logger{
Filename: logpath,
MaxSize: 10,
MaxBackups: 200,
MaxAge: 30,
Compress: true,
}

if cfg.LogInConsole {
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(lumberJackLogger))
}
return zap.Skip()
return zapcore.AddSync(lumberJackLogger)
}

func Info(message string, fields ...zapcore.Field) {
logger.Info(message, fields...)
}

func Error(message string, fields ...zapcore.Field) {
logger.Error(message, fields...)
}
24 changes: 12 additions & 12 deletions pkg/module/file.go
Original file line number Diff line number Diff line change
@@ -27,9 +27,9 @@ package module
import (
"errors"
"fmt"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"go.uber.org/zap"
"os"

log "github.com/opencurve/curveadm/pkg/log/glg"
)

const (
@@ -54,11 +54,11 @@ func (f *FileManager) Upload(localPath, remotePath string) error {
}

err := f.sshClient.Client().Upload(localPath, remotePath)
log.SwitchLevel(err)("UploadFile",
log.Field("remoteAddress", remoteAddr(f.sshClient)),
log.Field("localPath", localPath),
log.Field("remotePath", remotePath),
log.Field("error", err))
zaplog.Error("UploadFile",
zap.String("remoteAddress", remoteAddr(f.sshClient)),
zap.String("localPath", localPath),
zap.String("remotePath", remotePath),
zap.Any("error", err))
return err
}

@@ -68,11 +68,11 @@ func (f *FileManager) Download(remotePath, localPath string) error {
}

err := f.sshClient.Client().Download(remotePath, localPath)
log.SwitchLevel(err)("DownloadFile",
log.Field("remoteAddress", remoteAddr(f.sshClient)),
log.Field("remotePath", remotePath),
log.Field("localPath", localPath),
log.Field("error", err))
zaplog.Error("DownloadFile",
zap.String("remoteAddress", remoteAddr(f.sshClient)),
zap.String("remotePath", remotePath),
zap.String("localPath", localPath),
zap.Any("error", err))
return err
}

13 changes: 7 additions & 6 deletions pkg/module/module.go
Original file line number Diff line number Diff line change
@@ -28,13 +28,14 @@ import (
"bytes"
"context"
"fmt"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"go.uber.org/zap"
"os/exec"
"strings"
"text/template"
"time"

"github.com/melbahja/goph"
log "github.com/opencurve/curveadm/pkg/log/glg"
)

type (
@@ -145,10 +146,10 @@ func execCommand(sshClient *SSHClient,
err = &TimeoutError{options.ExecTimeoutSec}
}

log.SwitchLevel(err)("Execute command",
log.Field("remoteAddr", remoteAddr(sshClient)),
log.Field("command", command),
log.Field("output", strings.TrimSuffix(string(out), "\n")),
log.Field("error", err))
zaplog.Error("Execute command",
zap.String("remoteAddr", remoteAddr(sshClient)),
zap.String("command", command),
zap.String("output", strings.TrimSuffix(string(out), "\n")),
zap.Any("error", err))
return string(out), err
}
37 changes: 19 additions & 18 deletions pkg/module/ssh.go
Original file line number Diff line number Diff line change
@@ -26,11 +26,12 @@ package module

import (
"errors"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"go.uber.org/zap"
"net"
"time"

"github.com/melbahja/goph"
log "github.com/opencurve/curveadm/pkg/log/glg"
"golang.org/x/crypto/ssh"
)

@@ -107,13 +108,13 @@ func NewSSHClient(config SSHConfig) (*SSHClient, error) {
}

if err != nil {
log.Error("Create SSH auth",
log.Field("user", user),
log.Field("host", host),
log.Field("port", port),
log.Field("forwardAgent", forwardAgent),
log.Field("privateKeyPath", privateKeyPath),
log.Field("error", err))
zaplog.Error("Create SSH auth",
zap.String("user", user),
zap.String("host", host),
zap.Uint("port", port),
zap.Bool("forwardAgent", forwardAgent),
zap.String("privateKeyPath", privateKeyPath),
zap.Any("error", err))
return nil, err
}

@@ -129,16 +130,16 @@ connect:
Callback: VerifyHost,
})

log.SwitchLevel(err)("Connect remote SSH",
log.Field("user", user),
log.Field("host", host),
log.Field("port", port),
log.Field("forwardAgent", forwardAgent),
log.Field("privateKeyPath", privateKeyPath),
log.Field("timeoutSec", connTimeoutSec),
log.Field("maxRetries", maxRetries),
log.Field("tries", tries),
log.Field("error", err))
zaplog.Error("Connect remote SSH",
zap.String("user", user),
zap.String("host", host),
zap.Uint("port", port),
zap.Bool("forwardAgent", forwardAgent),
zap.String("privateKeyPath", privateKeyPath),
zap.Int("timeoutSec", connTimeoutSec),
zap.Int("maxRetries", maxRetries),
zap.Int("tries", tries),
zap.Any("error", err))

if err != nil {
if tries < maxRetries {
6 changes: 3 additions & 3 deletions pkg/variable/variables.go
Original file line number Diff line number Diff line change
@@ -26,9 +26,9 @@ package variable

import (
"fmt"
"github.com/opencurve/curveadm/pkg/log/zaplog"
"go.uber.org/zap"
"regexp"

log "github.com/opencurve/curveadm/pkg/log/glg"
)

const (
@@ -152,6 +152,6 @@ func (vars *Variables) Rendering(s string) (string, error) {

func (vars *Variables) Debug() {
for _, v := range vars.m {
log.Info("Variable", log.Field(v.Name, v.Value))
zaplog.Info("Variable", zap.String(v.Name, v.Value))
}
}