Logging with zap in cgo #1219
-
Is it possible to log with zap in cgo code? Or is it necessary to pass all log messages back up from the C layer to the Go layer in order to log with zap? (Of course, then the time when the log message would otherwise have been made will be lost, or if the program crashes before returning to the Go layer, the log messages will be lost.) If it is not possible to log with zap in cgo code, are there any plans to support this in the future? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @shanebishop, you can't log to Zap from C like that because Zap does not expose a C API. Even if Zap was able to expose C-level logging APIs, because all of Zap's logic is implemented in Go, the C environment would have to yield control back to the Go runtime for each log call, at which point this is moot again because it's vulnerable to the issues you're trying to avoid. |
Beta Was this translation helpful? Give feedback.
Hey @shanebishop, you can't log to Zap from C like that because Zap does not expose a C API. Even if Zap was able to expose C-level logging APIs, because all of Zap's logic is implemented in Go, the C environment would have to yield control back to the Go runtime for each log call, at which point this is moot again because it's vulnerable to the issues you're trying to avoid.