@@ -25,6 +25,7 @@ package cli
25
25
import (
26
26
"errors"
27
27
"fmt"
28
+ "go.uber.org/zap"
28
29
"io"
29
30
"os"
30
31
"path"
@@ -41,7 +42,7 @@ import (
41
42
tui "github.com/opencurve/curveadm/internal/tui/common"
42
43
"github.com/opencurve/curveadm/internal/utils"
43
44
cliutil "github.com/opencurve/curveadm/internal/utils"
44
- log "github.com/opencurve/curveadm/pkg/log/glg "
45
+ "github.com/opencurve/curveadm/pkg/log/zaplog "
45
46
"github.com/opencurve/curveadm/pkg/module"
46
47
)
47
48
@@ -131,15 +132,11 @@ func (curveadm *CurveAdm) init() error {
131
132
configure .ReplaceGlobals (config )
132
133
133
134
// (3) Init logger
134
- now := time .Now ().Format ("2006-01-02_15-04-05" )
135
- logpath := fmt .Sprintf ("%s/curveadm-%s.log" , curveadm .logDir , now )
136
- if err := log .Init (config .GetLogLevel (), logpath ); err != nil {
137
- return errno .ERR_INIT_LOGGER_FAILED .E (err )
138
- } else {
139
- log .Info ("Init logger success" ,
140
- log .Field ("LogPath" , logpath ),
141
- log .Field ("LogLevel" , config .GetLogLevel ()))
142
- }
135
+ logpath := fmt .Sprintf ("%s/curveadm.log" , curveadm .logDir )
136
+ zaplog .LOG = zaplog .Init (config , logpath )
137
+
138
+ zaplog .LOG .Info ("Init logger success" ,
139
+ zap .String ("LogPath" , logpath ))
143
140
144
141
// (4) Init error code
145
142
errno .Init (logpath )
@@ -148,17 +145,17 @@ func (curveadm *CurveAdm) init() error {
148
145
dbpath := fmt .Sprintf ("%s/curveadm.db" , curveadm .dataDir )
149
146
s , err := storage .NewStorage (dbpath )
150
147
if err != nil {
151
- log .Error ("Init SQLite database failed" ,
152
- log . Field ("Error" , err ))
148
+ zaplog . LOG .Error ("Init SQLite database failed" ,
149
+ zap . Any ("Error" , err ))
153
150
return errno .ERR_INIT_SQL_DATABASE_FAILED .E (err )
154
151
}
155
152
156
153
// (6) Get hosts
157
154
var hosts storage.Hosts
158
155
hostses , err := s .GetHostses ()
159
156
if err != nil {
160
- log .Error ("Get hosts failed" ,
161
- log . Field ("Error" , err ))
157
+ zaplog . LOG .Error ("Get hosts failed" ,
158
+ zap . Any ("Error" , err ))
162
159
return errno .ERR_GET_HOSTS_FAILED .E (err )
163
160
} else if len (hostses ) == 1 {
164
161
hosts = hostses [0 ]
@@ -167,20 +164,20 @@ func (curveadm *CurveAdm) init() error {
167
164
// (7) Get current cluster
168
165
cluster , err := s .GetCurrentCluster ()
169
166
if err != nil {
170
- log .Error ("Get current cluster failed" ,
171
- log . Field ("Error" , err ))
167
+ zaplog . LOG .Error ("Get current cluster failed" ,
168
+ zap . Any ("Error" , err ))
172
169
return errno .ERR_GET_CURRENT_CLUSTER_FAILED .E (err )
173
170
} else {
174
- log .Info ("Get current cluster success" ,
175
- log . Field ("ClusterId" , cluster .Id ),
176
- log . Field ("ClusterName" , cluster .Name ))
171
+ zaplog . LOG .Info ("Get current cluster success" ,
172
+ zap . Int ("ClusterId" , cluster .Id ),
173
+ zap . String ("ClusterName" , cluster .Name ))
177
174
}
178
175
179
176
// (8) Get Disks
180
177
var disks storage.Disks
181
178
diskses , err := s .GetDisks ()
182
179
if err != nil {
183
- log . Error ("Get disks failed" , log . Field ("Error" , err ))
180
+ zaplog . LOG . Error ("Get disks failed" , zap . Any ("Error" , err ))
184
181
return errno .ERR_GET_DISKS_FAILED .E (err )
185
182
} else if len (diskses ) > 0 {
186
183
disks = diskses [0 ]
@@ -189,7 +186,7 @@ func (curveadm *CurveAdm) init() error {
189
186
// (9) Get Disk Records
190
187
diskRecords , err := s .GetDisk (comm .DISK_FILTER_ALL )
191
188
if err != nil {
192
- log . Error ("Get disk records failed" , log . Field ("Error" , err ))
189
+ zaplog . LOG . Error ("Get disk records failed" , zap . Any ("Error" , err ))
193
190
return errno .ERR_GET_DISK_RECORDS_FAILED .E (err )
194
191
}
195
192
@@ -507,8 +504,8 @@ func (curveadm *CurveAdm) PreAudit(now time.Time, args []string) int64 {
507
504
id , err := curveadm .Storage ().InsertAuditLog (
508
505
now , cwd , command , comm .AUDIT_STATUS_ABORT )
509
506
if err != nil {
510
- log .Error ("Insert audit log failed" ,
511
- log . Field ("Error" , err ))
507
+ zaplog . LOG .Error ("Insert audit log failed" ,
508
+ zap . Any ("Error" , err ))
512
509
}
513
510
514
511
return id
@@ -521,8 +518,8 @@ func (curveadm *CurveAdm) PostAudit(id int64, ec error) {
521
518
522
519
auditLogs , err := curveadm .Storage ().GetAuditLog (id )
523
520
if err != nil {
524
- log .Error ("Get audit log failed" ,
525
- log . Field ("Error" , err ))
521
+ zaplog . LOG .Error ("Get audit log failed" ,
522
+ zap . Any ("Error" , err ))
526
523
return
527
524
} else if len (auditLogs ) != 1 {
528
525
return
@@ -544,7 +541,7 @@ func (curveadm *CurveAdm) PostAudit(id int64, ec error) {
544
541
545
542
err = curveadm .Storage ().SetAuditLogStatus (id , status , errorCode )
546
543
if err != nil {
547
- log .Error ("Set audit log status failed" ,
548
- log . Field ("Error" , err ))
544
+ zaplog . LOG .Error ("Set audit log status failed" ,
545
+ zap . Any ("Error" , err ))
549
546
}
550
547
}
0 commit comments