log.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "log.h"
  2. #include <log/pqlog.h>
  3. #include <iostream>
  4. #include <QThread>
  5. #include <QDebug>
  6. using namespace PQ;
  7. void testLog()
  8. {
  9. auto manger = PQLogManger::this_();
  10. std::cout << "保存位置: " << manger->getSaveFilePath().toStdString() << std::endl;
  11. logSeeting();
  12. defaultLog();
  13. nameLog();
  14. qtLog();
  15. }
  16. void logSeeting()
  17. {
  18. auto manger = PQLogManger::this_();
  19. auto log = manger->baseLog(); // 获取默认的日志
  20. log->setOutState(PQ::OutState::STD_OUT);// 设置输出位置
  21. auto mlog = manger->getLog("MyLOG"); // 获取自定义log
  22. mlog->setOutState(PQ::OutState::File); // 设置输出到文件
  23. mlog->fileCreateType = PQ::OnlyOne;// 设置都写入一个文件里
  24. }
  25. void nameLog()
  26. {
  27. auto mlog = PQLogManger::this_()->getLog("MyLOG");
  28. pqTest(mlog) << " test message";
  29. pqDebug(mlog) << "debug message";
  30. pqInfo(mlog) << "info message";
  31. pqWarning(mlog) << "warming message";
  32. pqCritical(mlog) << "error message";
  33. //pqFatal(mlog) << "fatal message";// 调用将退出程序
  34. mlog->level = PQ::InfoMsg;
  35. pqTest(mlog) << " test message 2";
  36. pqDebug(mlog) << "debug message 2";
  37. pqInfo(mlog) << "info message 2";
  38. pqWarning(mlog) << "warming message 2";
  39. pqCritical(mlog) << "error message 2";
  40. }
  41. void defaultLog()
  42. {
  43. auto log = PQLogManger::this_()->baseLog();
  44. pqTest(log) << " test message";
  45. pqDebug(log) << "debug message";
  46. pqInfo(log) << "info message";
  47. pqWarning(log) << "warming message";
  48. pqCritical(log) << "error message";
  49. // 下面是简便的宏设置
  50. pqDTest << " test message --2";
  51. pqDDebug << "debug message --2";
  52. pqDInfo<< "info message -- 2";
  53. pqDWarning << "warming message -- 2";
  54. pqDCritical << "error message --2";
  55. }
  56. void qtLog()
  57. {
  58. qDebug() << "this is 1 qdebug";
  59. PQLogManger::this_()->enbleQtMessage();// 开启接受Qt debug的信息
  60. QThread::msleep(50);
  61. qDebug() << "this is 2 qdebug";
  62. }