static std::string LogPrefix()

in sdk/src/utils/LogUtils.cc [38:63]


static std::string LogPrefix(LogLevel logLevel, const char* tag)
{
    static const char *LogStr[] = {"[OFF]", "[FATAL]", "[ERROR]", "[WARN]", "[INFO]" , "[DEBUG]", "[TRACE]", "[ALL]"};
    int index = logLevel - LogLevel::LogOff;
    std::stringstream ss;
    auto tp = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
    auto ms = tp.time_since_epoch().count() % 1000;
    auto t = std::chrono::system_clock::to_time_t(tp);
    struct tm tm;
#ifdef WIN32
    ::localtime_s(&tm, &t);
#else
    ::localtime_r(&t, &tm);
#endif
#if defined(__GNUG__) && __GNUC__ < 5
    char tmbuff[64];
    strftime(tmbuff, 64, "%Y-%m-%d %H:%M:%S.", &tm);
    ss << "[" << tmbuff << std::setw(3) << std::setfill('0') << ms << "]";
#else
    ss << "[" << std::put_time(&tm, "%Y-%m-%d %H:%M:%S.") << std::setw(3) << std::setfill('0') << ms << "]";
#endif
    ss << LogStr[index];
    ss << "[" << tag << "]";
    ss << "[" << std::this_thread::get_id() << "]";
    return ss.str();
}