| 642 | } |
| 643 | |
| 644 | void _debug(int line, code_part part, const char *function, const char *str, ...) |
| 645 | { |
| 646 | char outputBuffer[MAX_LEN_LOG_LINE]; |
| 647 | thread_local std::array<std::vector<char>, 2> inputBuffer = {std::vector<char>(MAX_LEN_LOG_LINE, 0), std::vector<char>(MAX_LEN_LOG_LINE, 0)}; |
| 648 | thread_local unsigned int repeated = 0; /* times current message repeated */ |
| 649 | thread_local unsigned int next = 2; /* next total to print update */ |
| 650 | thread_local unsigned int prev = 0; /* total on last update */ |
| 651 | |
| 652 | va_list ap; |
| 653 | va_start(ap, str); |
| 654 | vssprintf(outputBuffer, str, ap); |
| 655 | va_end(ap); |
| 656 | |
| 657 | if (part == LOG_WARNING) |
| 658 | { |
| 659 | bool addedNew = false; |
| 660 | { |
| 661 | std::lock_guard<std::mutex> guard(warning_list_mutex); |
| 662 | addedNew = warning_list.insert(std::pair<std::string, int>(std::string(function) + "-" + std::string(outputBuffer), line)).second; |
| 663 | } |
| 664 | if (addedNew) |
| 665 | { |
| 666 | auto& currInputBuffer = inputBuffer[useInputBuffer1 ? 1 : 0]; |
| 667 | snprintf(currInputBuffer.data(), currInputBuffer.size(), "[%s:%d] %s (**Further warnings of this type are suppressed.)", function, line, outputBuffer); |
| 668 | } |
| 669 | else |
| 670 | { |
| 671 | return; // don't bother adding any more |
| 672 | } |
| 673 | } |
| 674 | else |
| 675 | { |
| 676 | auto& currInputBuffer = inputBuffer[useInputBuffer1 ? 1 : 0]; |
| 677 | snprintf(currInputBuffer.data(), currInputBuffer.size(), "[%s:%d] %s", function, line, outputBuffer); |
| 678 | } |
| 679 | |
| 680 | if (strncmp(inputBuffer[0].data(), inputBuffer[1].data(), std::min(inputBuffer[0].size(), inputBuffer[1].size())) == 0) |
| 681 | { |
| 682 | // Received again the same line |
| 683 | repeated++; |
| 684 | if (repeated == next) |
| 685 | { |
| 686 | if (repeated > 2) |
| 687 | { |
| 688 | ssprintf(outputBuffer, "last message repeated %u times (total %u repeats)", repeated - prev, repeated); |
| 689 | } |
| 690 | else |
| 691 | { |
| 692 | ssprintf(outputBuffer, "last message repeated %u times", repeated - prev); |
| 693 | } |
| 694 | printToDebugCallbacks(outputBuffer, part); |
| 695 | prev = repeated; |
| 696 | next *= 2; |
| 697 | } |
| 698 | } |
| 699 | else |
| 700 | { |
| 701 | // Received another line, cleanup the old |
no test coverage detected