void tst_QLogSystem::qWarningOutput() { QFETCH(QString, fstr); QFETCH(int, intIn); QFETCH(QString, chIn); QFETCH(double, dlIn); QFETCH(QString, expected); FileLogger<LvlLogPrefix>* fileLogger = new FileLogger<LvlLogPrefix>("./LoggersTest.log"); fileLogger->setMinLogLvl(LlDbg); QString err_msg; QVERIFY2(fileLogger->isReady(err_msg), "File logger is not ready with local dir."); QVERIFY2(err_msg.isEmpty(), "File logger has obtained error message with local dir"); LogSystem::getInstance().addLogger(fileLogger); qWarning(qPrintable(fstr), intIn, qPrintable(chIn), dlIn); LogSystem::getInstance().clear(); QFile file("./LoggersTest.log"); QVERIFY2(file.open(QFile::ReadOnly), "Could not open log file for reading"); QByteArray dataBuf= file.readLine(); QCOMPARE(QString(dataBuf.data()), expected); file.close(); }
void tst_QLogSystem::minLogLvl() { FileLogger<LvlLogPrefix>* fileLogger = new FileLogger<LvlLogPrefix>("./LoggersTest.log"); char forbidden[] = "should not be shown!"; QString err_msg; QVERIFY2(fileLogger->isReady(err_msg), "File logger is not ready with local dir."); QVERIFY2(err_msg.isEmpty(), "File logger has obtained error message with local dir"); fileLogger->setMinLogLvl(LlWarning); LogSystem::getInstance().addLogger(fileLogger); LogSystem::getInstance().log(LlInfo, forbidden); LogSystem::getInstance().clear(); QFile file("./LoggersTest.log"); QVERIFY2(file.open(QFile::ReadOnly), "Could not open log file for reading"); QByteArray dataBuf= file.readLine(); file.close(); QVERIFY2(dataBuf.isEmpty(), "The logger has written record with invalid Log Level"); }