Output a debug string to local buffering, in a synchronized manner, and enqueue it for background output on the console. We do this because many of our debug routines are done at interrupt level, and fmt.Printf is notoriously slow.
(ctx context.Context, format string, args ...interface{})
| 197 | // output on the console. We do this because many of our debug routines are done at interrupt level, |
| 198 | // and fmt.Printf is notoriously slow. |
| 199 | func defaultLogger(ctx context.Context, format string, args ...interface{}) { |
| 200 | // Exit if not yet initialized |
| 201 | if !loggerInitialized { |
| 202 | defaultLoggerInit() |
| 203 | } |
| 204 | |
| 205 | message := fmt.Sprintf(format, args...) |
| 206 | |
| 207 | // Append to what's pending, unless the channel is full, in which case we drop it and move on |
| 208 | if synchronous { |
| 209 | fmt.Println(message) |
| 210 | } else { |
| 211 | select { |
| 212 | case loggerChannel <- message: |
| 213 | default: |
| 214 | // channel full |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // Initialize for debugging |
| 220 | func defaultLoggerInit() { |