| 586 | /************************************************************************/ |
| 587 | |
| 588 | static void CPLvDebug(const char *pszCategory, |
| 589 | CPL_FORMAT_STRING(const char *pszFormat), va_list args) |
| 590 | { |
| 591 | CPLErrorContext *psCtx = CPLGetErrorContext(); |
| 592 | if (psCtx == nullptr || IS_PREFEFINED_ERROR_CTX(psCtx)) |
| 593 | return; |
| 594 | const char *pszDebug = CPLGetConfigOption("CPL_DEBUG", nullptr); |
| 595 | |
| 596 | /* -------------------------------------------------------------------- */ |
| 597 | /* Does this message pass our current criteria? */ |
| 598 | /* -------------------------------------------------------------------- */ |
| 599 | if (pszDebug == nullptr || EQUAL(pszDebug, "NO") || |
| 600 | EQUAL(pszDebug, "OFF") || EQUAL(pszDebug, "FALSE") || |
| 601 | EQUAL(pszDebug, "0")) |
| 602 | { |
| 603 | return; |
| 604 | } |
| 605 | |
| 606 | if (!EQUAL(pszDebug, "ON") && !EQUAL(pszDebug, "YES") && |
| 607 | !EQUAL(pszDebug, "TRUE") && !EQUAL(pszDebug, "1") && |
| 608 | !EQUAL(pszDebug, "")) |
| 609 | { |
| 610 | // check if value of CPL_DEBUG contains the category |
| 611 | const size_t nLen = strlen(pszCategory); |
| 612 | |
| 613 | size_t i = 0; |
| 614 | for (i = 0; pszDebug[i] != '\0'; i++) |
| 615 | { |
| 616 | if (EQUALN(pszCategory, pszDebug + i, nLen)) |
| 617 | break; |
| 618 | } |
| 619 | |
| 620 | if (pszDebug[i] == '\0') |
| 621 | return; |
| 622 | } |
| 623 | |
| 624 | /* -------------------------------------------------------------------- */ |
| 625 | /* Allocate a block for the error. */ |
| 626 | /* -------------------------------------------------------------------- */ |
| 627 | const int ERROR_MAX = 25000; |
| 628 | char *pszMessage = static_cast<char *>(VSIMalloc(ERROR_MAX)); |
| 629 | if (pszMessage == nullptr) |
| 630 | return; |
| 631 | |
| 632 | /* -------------------------------------------------------------------- */ |
| 633 | /* Dal -- always log a timestamp as the first part of the line */ |
| 634 | /* to ensure one is looking at what one should be looking at! */ |
| 635 | /* -------------------------------------------------------------------- */ |
| 636 | |
| 637 | pszMessage[0] = '\0'; |
| 638 | #ifdef TIMESTAMP_DEBUG |
| 639 | if (CPLTestBool(CPLGetConfigOption("CPL_TIMESTAMP", "NO"))) |
| 640 | { |
| 641 | static struct CPLTimeVal tvStart; |
| 642 | static const auto unused = CPLGettimeofday(&tvStart, nullptr); |
| 643 | CPL_IGNORE_RET_VAL(unused); |
| 644 | struct CPLTimeVal tv; |
| 645 | CPLGettimeofday(&tv, nullptr); |
no test coverage detected