本文整理汇总了C++中LogFile类的典型用法代码示例。如果您正苦于以下问题:C++ LogFile类的具体用法?C++ LogFile怎么用?C++ LogFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LogFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
try
{
LogFile dummy;
dummy.write("Writing from main");
}
catch (const LogFileException& ex)
{
cerr << ex.what();
}
try
{
LogFile logFile("Exceptions.log");
logFile.write("Writing from main");
logFile.write("Writing from main - again");
}
catch (const LogFileException& ex)
{
cerr << ex.what();
}
getchar();
}
示例2: tr
/** Saves the given list of items to a file.
* \param items A list of log message items to save.
*/
void
MessageLog::save(const QStringList &messages)
{
if (!messages.size()) {
return;
}
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Log Messages"),
"VidaliaLog-" +
QDateTime::currentDateTime().toString("MM.dd.yyyy")
+ ".txt", tr("Text Files (*.txt)"));
/* If the choose to save */
if (!fileName.isEmpty()) {
LogFile logFile;
QString errmsg;
/* If can't write to file, show error message */
if (!logFile.open(fileName, &errmsg)) {
VMessageBox::warning(this, tr("Vidalia"),
p(tr("Cannot write file %1\n\n%2."))
.arg(fileName)
.arg(errmsg),
VMessageBox::Ok);
return;
}
/* Write out the message log to the file */
QApplication::setOverrideCursor(Qt::WaitCursor);
foreach (QString msg, messages) {
logFile << msg << "\n";
}
QApplication::restoreOverrideCursor();
}
示例3: main
int main() {
LogFile log;
thread t1(function_1, ref(log));
for(int i = 0; i < 1000; ++i)
log.shared_print2(string("From main: "), i);
t1.join();
return 0;
}
示例4: TEST_F
TEST_F(LinearLogFileTest, showValidLog) {
std::string TEST_DISPLAY("DISPLAY\n");
LogFile log;
log.Enable("./test.log");
log.Write(false, LOG_ERR, __FILE__, __LINE__, __PRETTY_FUNCTION__, TEST_DISPLAY.c_str());
log.Write(false, LOG_WARN, __FILE__, __LINE__, __PRETTY_FUNCTION__, TEST_DISPLAY.c_str());
log.Write(false, LOG_INFO, __FILE__, __LINE__, __PRETTY_FUNCTION__, TEST_DISPLAY.c_str());
log.Write(false, LOG_DEBUG, __FILE__, __LINE__, __PRETTY_FUNCTION__, TEST_DISPLAY.c_str());
}
示例5: main
int main()
{
LogFile log;
std::thread thread(function, std::ref(log));
for (int i = 0; i < 100; i++)
log.print(std::string("From main thread: "), i);
thread.join();
return 0;
}
示例6: AreEqual
bool AreEqual(const LogFile& a, const LogFile& b)
{
if (a.Count() != b.Count())
return false;
int count = a.Count();
for (int i = 0; i < count; ++i)
{
if (!AreEqual(a[i], b[i]))
return false;
}
return true;
}
示例7: main
int main() {
LogFile log;
Fctor fctor(log);
std::thread t1(fctor);
for (int i=0; i<100; i++)
log.shared_print("main", i);
t1.join();
return 0;
}
示例8: main
int main(int argc, char **argv)
{
LogFile log;
thread t1(SomeFunction, ref(log));
for(int index = 0; index < 100; index++)
{
log.logMsg02("From main ", index);
}
t1.join();// wait for t1 to finish.
return 0;
}
示例9: SomeFunction
void SomeFunction(LogFile& log)
{
for(int index = 0; index > -100 ; index--)
{
log.logMsg("From thread ", index);
}
}
示例10: 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));
}
示例11: 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";
}
示例12: lk
/* threading: only durThread() calls this, thus safe. */
void Journal::open() {
mutex::scoped_lock lk(_lfMutex);
assert( _lf == 0 );
string fname = getFilePathFor(nextFileNumber).string();
_lf = new LogFile(fname);
nextFileNumber++;
{
JHeader h(fname);
AlignedBuilder b(8192);
b.appendStruct(h);
_lf->synchronousAppend(b.buf(), b.len());
}
}
示例13: indexFileName
IndexFile::IndexFile(LogFile &logFile)
{
std::string indexFileName(logFile.getFileBaseName() + ".id2");
if(!loadIndexFile(indexFileName))
{
if(!createIndexFile(indexFileName, logFile))
{
throw std::runtime_error("Error building Index");
}
if(!loadIndexFile(indexFileName))
throw std::runtime_error("Internal Error, created index is corrupted");
}
}
示例14:
Application::Application()
{
MainApplication = this;
LF.Open("data/log_file.log",'w');
CF.Open("data/config.cfg",'r','t',false);
LF.Start("FJC 3D Engine");
}
示例15:
virtual void handleRec(const LogRecordPtr& rec)
{
if (logfile.isOpen() && !ignore(rec))
{
std::string msg;
formatLog(rec, msg);
hasWriten+= logfile.write(msg.c_str(), msg.length());
if (hasWriten >= flushEvery) {
logfile.flush();
hasWriten -= flushEvery;
}
}
}