| 203 | } |
| 204 | |
| 205 | void AsyncLogWriter::enqueue(QtMsgType type, |
| 206 | const QTime& timestamp, |
| 207 | const QString& category, |
| 208 | const QString& message) |
| 209 | { |
| 210 | { |
| 211 | std::lock_guard lock(m_mutex); |
| 212 | if (!m_started || !m_accepting) |
| 213 | return; |
| 214 | |
| 215 | if (m_queue.size() >= kMaxQueueEntries) { |
| 216 | if (isDebugOrInfo(type)) { |
| 217 | ++m_counters.droppedDebugInfoLines; |
| 218 | ++m_pendingDroppedDebugInfo; |
| 219 | m_cv.notify_one(); |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | auto dropIt = std::find_if(m_queue.begin(), m_queue.end(), |
| 224 | [](const QueueItem& item) { |
| 225 | return item.kind == ItemKind::Log && isDebugOrInfo(item.log.type); |
| 226 | }); |
| 227 | if (dropIt != m_queue.end()) { |
| 228 | m_queue.erase(dropIt); |
| 229 | ++m_counters.droppedDebugInfoLines; |
| 230 | ++m_pendingDroppedDebugInfo; |
| 231 | } else if (m_queue.size() >= kHardMaxQueueEntries) { |
| 232 | ++m_counters.droppedHighPriorityLines; |
| 233 | ++m_pendingDroppedHighPriority; |
| 234 | m_cv.notify_one(); |
| 235 | return; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | QueueItem item; |
| 240 | item.kind = ItemKind::Log; |
| 241 | item.log.type = type; |
| 242 | item.log.timestamp = timestamp; |
| 243 | item.log.category = category; |
| 244 | item.log.message = message; |
| 245 | m_queue.push_back(std::move(item)); |
| 246 | |
| 247 | ++m_counters.queuedLines; |
| 248 | m_counters.maxQueueDepth = std::max<quint64>(m_counters.maxQueueDepth, m_queue.size()); |
| 249 | } |
| 250 | m_cv.notify_one(); |
| 251 | } |
| 252 | |
| 253 | void AsyncLogWriter::flush() |
| 254 | { |