-
Notifications
You must be signed in to change notification settings - Fork 72
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 #230
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the date-related information removed from the log name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The content of the same file reaches the specified number to be compressed. Passing the date will result in too many small files and cannot be cleared |
||
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)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,6 @@ import ( | |
"github.com/spf13/cobra" | ||
) | ||
|
||
|
||
var ( | ||
RESTART_PLAYBOOK_STEPS = []int{ | ||
playbook.RESTART_SERVICE, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build debug | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go fmt |
||
// +build debug | ||
|
||
package build | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build !debug | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go fmt |
||
// +build !debug | ||
|
||
package build | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can keeps your changes small.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done