Skip to content

Commit cb16a2e

Browse files
committed
print logs as string messages
1 parent 10e393a commit cb16a2e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

cmd/pbm/diagnostic.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/percona/percona-backup-mongodb/pbm/backup"
1313
"github.com/percona/percona-backup-mongodb/pbm/errors"
14+
"github.com/percona/percona-backup-mongodb/pbm/log"
1415
"github.com/percona/percona-backup-mongodb/sdk"
1516
)
1617

@@ -133,16 +134,12 @@ func writeLogToFile(ctx context.Context, pbm *sdk.Client, opts diagnosticOptions
133134
return errors.Wrap(err, "log: decode")
134135
}
135136

136-
data, err := bson.MarshalExtJSON(rec, true, true)
137-
if err != nil {
138-
return errors.Wrap(err, "log: encode")
139-
}
140-
141-
n, err := file.Write(data)
137+
s := rec.Stringify(log.AsUTC, true, true)
138+
n, err := file.WriteString(s)
142139
if err != nil {
143140
return errors.Wrap(err, "log: write")
144141
}
145-
if n != len(data) {
142+
if n != len(s) {
146143
return errors.Wrap(io.ErrShortWrite, "log")
147144
}
148145

pbm/log/history.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,23 @@ func (e *Entry) Stringify(f tsFormatFn, showNode, extr bool) string {
5858
}
5959

6060
func (e *Entry) String() string {
61-
return e.Stringify(tsLocal, false, false)
61+
return e.Stringify(AsLocal, false, false)
6262
}
6363

6464
func (e *Entry) StringNode() string {
65-
return e.Stringify(tsLocal, true, false)
65+
return e.Stringify(AsLocal, true, false)
6666
}
6767

68-
func tsLocal(ts int64) string {
68+
func AsLocal(ts int64) string {
6969
//nolint:gosmopolitan
7070
return time.Unix(ts, 0).Local().Format(LogTimeFormat)
7171
}
7272

73+
func AsUTC(ts int64) string {
74+
//nolint:gosmopolitan
75+
return time.Unix(ts, 0).UTC().Format(LogTimeFormat)
76+
}
77+
7378
type LogKeys struct {
7479
Severity Severity `bson:"s" json:"s"`
7580
RS string `bson:"rs" json:"rs"`

0 commit comments

Comments
 (0)