Skip to content

Commit

Permalink
print logs as string messages
Browse files Browse the repository at this point in the history
  • Loading branch information
defbin committed Nov 14, 2024
1 parent 3edfcd7 commit f446fd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 4 additions & 7 deletions cmd/pbm/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/percona/percona-backup-mongodb/pbm/backup"
"github.com/percona/percona-backup-mongodb/pbm/errors"
"github.com/percona/percona-backup-mongodb/pbm/log"
"github.com/percona/percona-backup-mongodb/sdk"
)

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

data, err := bson.MarshalExtJSON(rec, true, true)
if err != nil {
return errors.Wrap(err, "log: encode")
}

n, err := file.Write(data)
s := rec.Stringify(log.AsUTC, true, true)
n, err := file.WriteString(s)
if err != nil {
return errors.Wrap(err, "log: write")
}
if n != len(data) {
if n != len(s) {
return errors.Wrap(io.ErrShortWrite, "log")
}

Expand Down
11 changes: 8 additions & 3 deletions pbm/log/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@ func (e *Entry) Stringify(f tsFormatFn, showNode, extr bool) string {
}

func (e *Entry) String() string {
return e.Stringify(tsLocal, false, false)
return e.Stringify(AsLocal, false, false)
}

func (e *Entry) StringNode() string {
return e.Stringify(tsLocal, true, false)
return e.Stringify(AsLocal, true, false)
}

func tsLocal(ts int64) string {
func AsLocal(ts int64) string {
//nolint:gosmopolitan
return time.Unix(ts, 0).Local().Format(LogTimeFormat)
}

func AsUTC(ts int64) string {
//nolint:gosmopolitan
return time.Unix(ts, 0).UTC().Format(LogTimeFormat)
}

type LogKeys struct {
Severity Severity `bson:"s" json:"s"`
RS string `bson:"rs" json:"rs"`
Expand Down

0 comments on commit f446fd5

Please sign in to comment.