queueLog adds a log to the buffer and debounces a timer if one exists to flush the logs. It stores a maximum of 100 log lines before flushing as a safe-guard mechanism.
(ctx context.Context, log *proto.Log)
| 1157 | // if one exists to flush the logs. It stores a maximum of |
| 1158 | // 100 log lines before flushing as a safe-guard mechanism. |
| 1159 | func (r *Runner) queueLog(ctx context.Context, log *proto.Log) { |
| 1160 | r.mutex.Lock() |
| 1161 | defer r.mutex.Unlock() |
| 1162 | r.queuedLogs = append(r.queuedLogs, log) |
| 1163 | if r.flushLogsTimer != nil { |
| 1164 | r.flushLogsTimer.Reset(r.logBufferInterval) |
| 1165 | return |
| 1166 | } |
| 1167 | // This can be configurable if there are a ton of logs. |
| 1168 | if len(r.queuedLogs) > 100 { |
| 1169 | // Flushing logs requires a lock, so this can happen async. |
| 1170 | go r.flushQueuedLogs(ctx) |
| 1171 | return |
| 1172 | } |
| 1173 | r.flushLogsTimer = time.AfterFunc(r.logBufferInterval, func() { |
| 1174 | r.flushQueuedLogs(ctx) |
| 1175 | }) |
| 1176 | } |
| 1177 | |
| 1178 | func (r *Runner) flushQueuedLogs(ctx context.Context) { |
| 1179 | r.mutex.Lock() |
no test coverage detected