logproc.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef LOGPROC
  2. #define LOGPROC
  3. #include <QFile>
  4. #include <QString>
  5. #include <QDateTime>
  6. #include <QMessageBox>
  7. #include <QDebug>
  8. #include "CAppInfo.h"
  9. #include "CLogTrack.h"
  10. #define myDebug() (qDebug()<<__FILE__ << __LINE__<<",")
  11. #define myServerLog() (qInfo()<<__FILE__ << __LINE__<<",")
  12. static void CustomOutputMessage(QtMsgType type,
  13. const QMessageLogContext &context,
  14. const QString &msg)
  15. {
  16. QString message_type;
  17. QString current_date = QDateTime::currentDateTime().
  18. toString("yyyy-MM-dd hh:mm:ss");
  19. switch(type)
  20. {
  21. case QtInfoMsg:
  22. {
  23. QFile file("coe.cfgs");
  24. file.open(QIODevice::WriteOnly | QIODevice::Append);
  25. QString message = QString("%1,%2\r\n").arg(current_date).
  26. arg(msg);
  27. file.write(message.toLocal8Bit());
  28. file.close();
  29. if(g_logPtr)
  30. {
  31. CLogData ld;
  32. ld.pushLog("action", "CustomMessage");
  33. ld.pushLog("function", context.function);
  34. ld.pushLog("machineId", g_appInfoPtr->m_sMachineId);
  35. ld.pushLog("studentId", QString::number(g_appInfoPtr->m_nStudentId));
  36. ld.pushLog("msg", msg);
  37. ld.pushLog("clientTime", current_date);
  38. g_logPtr->putLog(ld);
  39. }
  40. }
  41. break;
  42. case QtDebugMsg:
  43. {
  44. if(g_appInfoPtr->m_bShowDebugInfo)
  45. {
  46. QFile file("coe.cfgl");
  47. file.open(QIODevice::WriteOnly | QIODevice::Append);
  48. QString message = QString("%1,%2\r\n").arg(current_date).
  49. arg(msg);
  50. file.write(message.toLocal8Bit());
  51. file.close();
  52. }
  53. }
  54. break;
  55. default:
  56. break;
  57. }
  58. }
  59. #endif // LOGPROC