Skip to content

Commit

Permalink
fixup! premain: enable JSON formatted logs if env var is set
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Weiße <[email protected]>
  • Loading branch information
daniel-weisse committed Nov 20, 2024
1 parent 91680af commit a4141ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cmd/premain-libos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ func exitStdLog(format string, args ...interface{}) {
func main() {
exit = exitStdLog
if strings.EqualFold(util.Getenv(constants.EnvLogFormat, ""), constants.LogFormatJSON) {
zapLogger, err := premain.LogJSON()
zapLog, err := premain.LogJSON()
if err != nil {
exit("failed to initialize logger: %s", err)
}
defer zapLog.Sync()

exit = func(format string, args ...interface{}) {
zapLogger.Fatal(fmt.Sprintf(format, args...))
zapLog.Fatal(fmt.Sprintf(format, args...))
}
}

Expand Down
5 changes: 3 additions & 2 deletions marble/premain/premain.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func LogJSON() (*zap.Logger, error) {
if err != nil {
return nil, err
}
defer zapLogger.Sync()
zap.RedirectStdLog(zapLogger)
return zapLogger, nil
}
Expand Down Expand Up @@ -140,9 +139,11 @@ func PreMainMock() error {
//nolint:revive
func PreMainEx(issuer quote.Issuer, activate ActivateFunc, hostfs, enclavefs afero.Fs) error {
if strings.EqualFold(util.Getenv(constants.EnvLogFormat, ""), constants.LogFormatJSON) {
if _, err := LogJSON(); err != nil {
zapLog, err := LogJSON()
if err != nil {
return err
}
defer zapLog.Sync()
}

prefixBackup := log.Prefix()
Expand Down

0 comments on commit a4141ec

Please sign in to comment.