#include "log.h"
#include <log/pqlog.h>
#include <iostream>
#include <QThread>
#include <QDebug>

using namespace PQ;

void testLog()
{
 auto manger =  PQLogManger::this_();
 std::cout << "保存位置： " << manger->getSaveFilePath().toStdString() << std::endl;

 logSeeting();

 defaultLog();

 nameLog();

 qtLog();
}

void logSeeting()
{
    auto manger =  PQLogManger::this_();
    auto log = manger->baseLog(); // 获取默认的日志
    log->setOutState(PQ::OutState::STD_OUT);// 设置输出位置
    auto mlog = manger->getLog("MyLOG"); // 获取自定义log
    mlog->setOutState(PQ::OutState::File); // 设置输出到文件
    mlog->fileCreateType = PQ::OnlyOne;// 设置都写入一个文件里
}

void nameLog()
{
    auto mlog = PQLogManger::this_()->getLog("MyLOG");
    pqTest(mlog) << " test message";
    pqDebug(mlog) << "debug message";
    pqInfo(mlog) << "info message";
    pqWarning(mlog) << "warming message";
    pqCritical(mlog) << "error message";
    //pqFatal(mlog) << "fatal message";//  调用将退出程序
    mlog->level = PQ::InfoMsg;
    pqTest(mlog) << " test message  2";
    pqDebug(mlog) << "debug message  2";
    pqInfo(mlog) << "info message  2";
    pqWarning(mlog) << "warming message  2";
    pqCritical(mlog) << "error message  2";
}

void defaultLog()
{
    auto log = PQLogManger::this_()->baseLog();
    pqTest(log) << " test message";
    pqDebug(log) << "debug message";
    pqInfo(log) << "info message";
    pqWarning(log) << "warming message";
    pqCritical(log) << "error message";
    // 下面是简便的宏设置
    pqDTest << " test message --2";
    pqDDebug << "debug message --2";
    pqDInfo<< "info message -- 2";
    pqDWarning << "warming message -- 2";
    pqDCritical << "error message --2";
}

void qtLog()
{

    qDebug() << "this is 1 qdebug";

    PQLogManger::this_()->enbleQtMessage();// 开启接受Qt debug的信息
    QThread::msleep(50);
    qDebug() << "this is 2 qdebug";
}
