CLogTrack.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef CLOGTRACK_H
  2. #define CLOGTRACK_H
  3. #include <list>
  4. #include <QString>
  5. #include <map>
  6. #include <thread>
  7. #include <mutex>
  8. #include <QWidget>
  9. #include "CHttpClient.h"
  10. namespace LOG_CONSTANT_DEF
  11. {
  12. const char* const LOG_API_VERSION = "0.6.0";
  13. const char* const X_LOG_APIVERSION = "x-log-apiversion";
  14. const char* const X_LOG_BODYRAWSIZE = "x-log-bodyrawsize";
  15. const char* const SOURCE = "__source__";
  16. const char* const WIN = "win";
  17. const char* const LOGS = "__logs__";
  18. };
  19. struct OC
  20. {
  21. OC() { oc = std::make_shared<std::once_flag >();}
  22. std::shared_ptr<std::once_flag> oc;
  23. int a;
  24. };
  25. class CLogInfo
  26. {
  27. public:
  28. QString sKey;
  29. QString sValue;
  30. CLogInfo()
  31. {
  32. sKey = "";
  33. sValue = "";
  34. }
  35. };
  36. class CLogData
  37. {
  38. public:
  39. CLogData();
  40. ~CLogData();
  41. QString genLogJson();
  42. void pushLog(QString sKey, QString sValue);
  43. private:
  44. std::vector<CLogInfo> m_LogList;
  45. };
  46. class CLogTrack : public QObject
  47. {
  48. Q_OBJECT
  49. public:
  50. CLogTrack(QString sProjectName, QString sEndpoint, QString sLogstore);
  51. ~CLogTrack();
  52. void putLog(CLogData log);
  53. signals:
  54. // void logFaild(OC oc);
  55. private:
  56. void threadProc();
  57. std::thread m_thread;
  58. bool m_bIsRun;
  59. std::list<CLogData> m_LogList;
  60. std::mutex m_logMutex;
  61. CHttpClient m_httpClient;
  62. QString m_sUrl;
  63. };
  64. extern std::shared_ptr<CLogTrack> g_logPtr;
  65. //class base : public QWidget
  66. //{
  67. // Q_OBJECT
  68. //public:
  69. // base(QWidget *parent = nullptr) : QWidget(parent)
  70. // {
  71. // qRegisterMetaType<OC>("OC");
  72. // connect(g_logPtr.get(), &CLogTrack::logFaild, this, &base::logFaild);
  73. // }
  74. //private slots:
  75. // virtual void logFaild(OC oc)
  76. // {
  77. // std::call_once(*oc.oc.get(), []() {
  78. // });
  79. // }
  80. //};
  81. #endif // CLOGTRACK_H