RequireLoggerFromContext returns a logger from context, panics if not found This should be used almost
(ctx context.Context)
| 171 | // RequireLoggerFromContext returns a logger from context, panics if not found |
| 172 | // This should be used almost |
| 173 | func RequireLoggerFromContext(ctx context.Context) Logger { |
| 174 | val := getLoggerFromContext(ctx) |
| 175 | if val == nil { |
| 176 | const size = 64 << 10 |
| 177 | stackTraceBuffer := make([]byte, size) |
| 178 | stackSize := runtime.Stack(stackTraceBuffer, false) |
| 179 | // Free up the unused spaces |
| 180 | stackTraceBuffer = stackTraceBuffer[:stackSize] |
| 181 | fmt.Fprintf(os.Stderr, "no logger in context Call stack:\n%s", |
| 182 | stackTraceBuffer) |
| 183 | |
| 184 | panic("logger not found in context") |
| 185 | } |
| 186 | return val |
| 187 | } |
| 188 | |
| 189 | // GetLoggerFromContextOrNil returns a logger from context, returns nil if not found |
| 190 | // You probably should use one of the other functions that return a logger instead of this one |