Skip to content

Commit

Permalink
Merge pull request #282 from spacemeshos/fix-crash-when-using-noop-za…
Browse files Browse the repository at this point in the history
…p-logger

Fix passing invalid log level to postrs logger
  • Loading branch information
poszu authored Mar 20, 2024
2 parents 8638344 + 272cb23 commit d102bed
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/postrs/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ var (
)

func setLogCallback(logger *zap.Logger) {
oncer.Do(func() {
C.set_logging_callback(levelMap[logger.Level()], C.callback(C.logCallback))
})
level, ok := levelMap[logger.Level()]
if !ok {
logger.Error("failed to map zap log level to C log level", zap.Stringer("level", logger.Level()))
return
}

logMux.Lock()
defer logMux.Unlock()
log = logger
logMux.Unlock()

oncer.Do(func() {
C.set_logging_callback(level, C.callback(C.logCallback))
})
}

//export logCallback
Expand Down

0 comments on commit d102bed

Please sign in to comment.