本文整理汇总了C++中LogFile::setThreadSafe方法的典型用法代码示例。如果您正苦于以下问题:C++ LogFile::setThreadSafe方法的具体用法?C++ LogFile::setThreadSafe怎么用?C++ LogFile::setThreadSafe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogFile
的用法示例。
在下文中一共展示了LogFile::setThreadSafe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bench
void bench(int type)
{
LogFile logfile;
int total = 0;
const bool kLongLog = false;
string longStr(3000, 'X');
if (type == 0)
{
}
else if (type == 1)
{
LOG_CONSOLE_OUTPUT(false);
logfile.setThreadSafe(false);
LOG_SET_LOGHANDLER(std::bind(&LogFile::dumpLog, &logfile, std::placeholders::_1, std::placeholders::_2));
}
else if (type == 2)
{
}
printf("one message size : [%d]\n", (strlen(data) + strlen(prefix)));
Timestamp start(Timestamp::now());
for (int i = 0; i < max_loop; ++i)
{
LOG_NOTICE(data);
}
Timestamp end(Timestamp::now());
total = max_loop * (strlen(data) + strlen(prefix));
double seconds = Timestamp::timeDiff(end, start);
const char *typestr = "unknown";
if (type == 0)
typestr = "console";
else if (type == 1)
typestr = "LogFile";
else if (type == 2)
typestr = "AsyncLogger";
printf("%12s: %f seconds, %d bytes, %10.2f msg/s, %.2f MiB/s\n", typestr, seconds, total, max_loop / seconds, total / seconds / (1024 * 1024));
}
示例2: test_logfile
void test_logfile()
{
LogFile logfile; // LogFile 需要保证在整个程序运行期间不能析构,且只应该创建一个LogFile对象(SingleTon?)
logfile.setThreadSafe(false); // 这里的测试是单线程的,所以可以设置不使用线程(内部不会加锁),否则的话需要设置为多线安全的(默认值)
// 下句可以不用调用,该类对象构造的时候进行了设置(注意资源竞态的可能,所有该对象应该最早创建)
//LOG_SET_LOGHANDLER(std::bind(&LogFile::dumpLog, &logfile, std::placeholders::_1, std::placeholders::_2));
LOG_DEBUG("This is a LOG_DEBUG msg!");
LOG_INFO("This is a LOG_INFO msg!");
LOG_NOTICE("This is a LOG_NOTICE msg!");
LOG_WARN("This is a LOG_WARN msg!");
LOG_ERROR("This is a LOG_ERROR msg!");
LOG_CRITICA("This is a LOG_CRITICA msg!");
LOG_ALERT("This is a LOG_ALERT msg!");
LOG_EMERGENCY("This is a LOG_EMERGENCY msg!");
cout << "####### test_logfile ########\n";
}