Exemplo n.º 1
0
    void _reportHead(const char* modName, const char* sourceInfo, Level severity)
    {
        std::chrono::steady_clock::duration tm = CurrentUptime();
        double tmd = tm.count() *
            std::chrono::steady_clock::duration::period::num /
            (double)std::chrono::steady_clock::duration::period::den;
        std::thread::id thrId = std::this_thread::get_id();
        const char* thrName = nullptr;
        if (ThreadMap.find(thrId) != ThreadMap.end())
            thrName = ThreadMap[thrId];

        fprintf(fp, "[");
        fprintf(fp, "%5.4f ", tmd);
        uint_fast64_t fIdx = FrameIndex.load();
        if (fIdx)
            fprintf(fp, "(%" PRIu64 ") ", fIdx);
        switch (severity)
        {
        case Info:
            fprintf(fp, "INFO");
            break;
        case Warning:
            fprintf(fp, "WARNING");
            break;
        case Error:
            fprintf(fp, "ERROR");
            break;
        case Fatal:
            fprintf(fp, "FATAL ERROR");
            break;
        default:
            break;
        };
        fprintf(fp, " %s", modName);
        if (sourceInfo)
            fprintf(fp, " {%s}", sourceInfo);
        if (thrName)
            fprintf(fp, " (%s)", thrName);
        fprintf(fp, "] ");
    }
Exemplo n.º 2
0
    static void _reportHead(const char* modName, const char* sourceInfo, Level severity)
    {
        /* Clear current line out */
        int width = ConsoleWidth();
        fprintf(stderr, "\r");
        for (int w=0 ; w<width ; ++w)
            fprintf(stderr, " ");
        fprintf(stderr, "\r");

        std::chrono::steady_clock::duration tm = CurrentUptime();
        double tmd = tm.count() *
            std::chrono::steady_clock::duration::period::num /
            (double)std::chrono::steady_clock::duration::period::den;
        std::thread::id thrId = std::this_thread::get_id();
        const char* thrName = nullptr;
        if (ThreadMap.find(thrId) != ThreadMap.end())
            thrName = ThreadMap[thrId];

        if (XtermColor)
        {
            fprintf(stderr, BOLD "[");
            fprintf(stderr, GREEN "%5.4f ", tmd);
            uint_fast64_t fIdx = FrameIndex.load();
            if (fIdx)
                fprintf(stderr, "(%" PRIu64 ") ", fIdx);
            switch (severity)
            {
                case Info:
                    fprintf(stderr, BOLD CYAN "INFO");
                    break;
                case Warning:
                    fprintf(stderr, BOLD YELLOW "WARNING");
                    break;
                case Error:
                    fprintf(stderr, RED BOLD "ERROR");
                    break;
                case Fatal:
                    fprintf(stderr, BOLD RED "FATAL ERROR");
                    break;
                default:
                    break;
            };
            fprintf(stderr, NORMAL BOLD " %s", modName);
            if (sourceInfo)
                fprintf(stderr, BOLD YELLOW " {%s}", sourceInfo);
            if (thrName)
                fprintf(stderr, BOLD MAGENTA " (%s)", thrName);
            fprintf(stderr, NORMAL BOLD "] " NORMAL);
        }
        else
        {
#if _WIN32
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_WHITE);
            fprintf(stderr, "[");
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
            fprintf(stderr, "%5.4f ", tmd);
            uint64_t fi = FrameIndex.load();
            if (fi)
                fprintf(stderr, "(%" PRIu64 ") ", fi);
            switch (severity)
            {
            case Info:
                SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
                fprintf(stderr, "INFO");
                break;
            case Warning:
                SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
                fprintf(stderr, "WARNING");
                break;
            case Error:
                SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_RED);
                fprintf(stderr, "ERROR");
                break;
            case Fatal:
                SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_RED);
                fprintf(stderr, "FATAL ERROR");
                break;
            default:
                break;
            };
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_WHITE);
            fprintf(stderr, " %s", modName);
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
            if (sourceInfo)
                fprintf(stderr, " {%s}", sourceInfo);
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
            if (thrName)
                fprintf(stderr, " (%s)", thrName);
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_WHITE);
            fprintf(stderr, "] ");
            SetConsoleTextAttribute(Term, FOREGROUND_WHITE);
#else
            fprintf(stderr, "[");
            fprintf(stderr, "%5.4f ", tmd);
            uint_fast64_t fIdx = FrameIndex.load();
            if (fIdx)
                fprintf(stderr, "(%" PRIu64 ") ", fIdx);
            switch (severity)
            {
            case Info:
                fprintf(stderr, "INFO");
                break;
            case Warning:
                fprintf(stderr, "WARNING");
                break;
            case Error:
                fprintf(stderr, "ERROR");
                break;
            case Fatal:
                fprintf(stderr, "FATAL ERROR");
                break;
            default:
                break;
            };
            fprintf(stderr, " %s", modName);
            if (sourceInfo)
                fprintf(stderr, " {%s}", sourceInfo);
            if (thrName)
                fprintf(stderr, " (%s)", thrName);
            fprintf(stderr, "] ");
#endif
        }
    }