What is DPanic and when to use it
masterDPanic (Development Panic) is a log level designed for errors that are theoretically possible but should never actually occur in a healthy system.
- In Development: It logs at
PanicLevel(triggering a panic). - In Production: It logs at
ErrorLevel(without crashing).
Use DPanic instead of a standard panic() to catch logic errors during development without risking application crashes in production environments.
// Instead of this:
if err != nil {
panic(fmt.Sprintf("shouldn't ever get here: %v", err))
}
// Use DPanic:
logger.DPanic("shouldn't ever get here", zap.Error(err))