当前位置: 首页>>代码示例>>C++>>正文


C++ LogFile类代码示例

本文整理汇总了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();
}
开发者ID:Todtaure,项目名称:ITAPK_Exercises,代码行数:25,代码来源:ProgramTransformation.cpp

示例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();
  }
开发者ID:Bodyfarm,项目名称:vidalia,代码行数:38,代码来源:MessageLog.cpp

示例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;
}
开发者ID:idontknoooo,项目名称:My_code,代码行数:8,代码来源:4-deadlock.cpp

示例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());
}
开发者ID:yujiono,项目名称:linear-cpp,代码行数:10,代码来源:log_file_test.cpp

示例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;
}
开发者ID:Adriqun,项目名称:C-CPP-SDL2,代码行数:11,代码来源:main.cpp

示例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;
}
开发者ID:bekdepostan,项目名称:DebugViewPP,代码行数:12,代码来源:DebugView++Test.cpp

示例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;
}
开发者ID:MiichaelD,项目名称:c_cpp,代码行数:12,代码来源:threads_3_mutex_file.cpp

示例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;
}
开发者ID:KunjeshBaghel,项目名称:CPP01,代码行数:14,代码来源:Concept03.cpp

示例9: SomeFunction

void SomeFunction(LogFile& log)
{
    for(int index = 0; index > -100 ; index--)
    {
        log.logMsg("From thread  ", index);
    }
}
开发者ID:KunjeshBaghel,项目名称:CPP01,代码行数:7,代码来源:Concept03.cpp

示例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));
}
开发者ID:Redi0,项目名称:CppLanguagePrograms,代码行数:45,代码来源:Logger_test.cpp

示例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";
}
开发者ID:Redi0,项目名称:CppLanguagePrograms,代码行数:18,代码来源:Logger_test.cpp

示例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());
     }
 }
开发者ID:jit,项目名称:mongo,代码行数:14,代码来源:dur_journal.cpp

示例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");
    }
}
开发者ID:marvin2k,项目名称:tools-pocolog_cpp,代码行数:13,代码来源:IndexFile.cpp

示例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");
}
开发者ID:firej,项目名称:OGL2,代码行数:8,代码来源:ApplicationClass.cpp

示例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;
				}
			}
		}
开发者ID:John-Chan,项目名称:logcpp-prebuild,代码行数:13,代码来源:def_appender.hpp


注:本文中的LogFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。