ImageLogging.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #ifndef mozilla_image_ImageLogging_h
  7. #define mozilla_image_ImageLogging_h
  8. #include "mozilla/Logging.h"
  9. #include "prinrval.h"
  10. static mozilla::LazyLogModule gImgLog("imgRequest");
  11. #define GIVE_ME_MS_NOW() PR_IntervalToMilliseconds(PR_IntervalNow())
  12. using mozilla::LogLevel;
  13. class LogScope {
  14. public:
  15. LogScope(mozilla::LogModule* aLog, void* aFrom, const char* aFunc)
  16. : mLog(aLog)
  17. , mFrom(aFrom)
  18. , mFunc(aFunc)
  19. {
  20. MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s {ENTER}\n",
  21. GIVE_ME_MS_NOW(), mFrom, mFunc));
  22. }
  23. /* const char * constructor */
  24. LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
  25. const char* paramName, const char* paramValue)
  26. : mLog(aLog)
  27. , mFrom(from)
  28. , mFunc(fn)
  29. {
  30. MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n",
  31. GIVE_ME_MS_NOW(), mFrom, mFunc,
  32. paramName, paramValue));
  33. }
  34. /* void ptr constructor */
  35. LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
  36. const char* paramName, const void* paramValue)
  37. : mLog(aLog)
  38. , mFrom(from)
  39. , mFunc(fn)
  40. {
  41. MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=%p) {ENTER}\n",
  42. GIVE_ME_MS_NOW(), mFrom, mFunc,
  43. paramName, paramValue));
  44. }
  45. /* int32_t constructor */
  46. LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
  47. const char* paramName, int32_t paramValue)
  48. : mLog(aLog)
  49. , mFrom(from)
  50. , mFunc(fn)
  51. {
  52. MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
  53. GIVE_ME_MS_NOW(), mFrom, mFunc,
  54. paramName, paramValue));
  55. }
  56. /* uint32_t constructor */
  57. LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
  58. const char* paramName, uint32_t paramValue)
  59. : mLog(aLog)
  60. , mFrom(from)
  61. , mFunc(fn)
  62. {
  63. MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
  64. GIVE_ME_MS_NOW(), mFrom, mFunc,
  65. paramName, paramValue));
  66. }
  67. ~LogScope()
  68. {
  69. MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s {EXIT}\n",
  70. GIVE_ME_MS_NOW(), mFrom, mFunc));
  71. }
  72. private:
  73. mozilla::LogModule* mLog;
  74. void* mFrom;
  75. const char* mFunc;
  76. };
  77. class LogFunc {
  78. public:
  79. LogFunc(mozilla::LogModule* aLog, void* from, const char* fn)
  80. {
  81. MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s\n",
  82. GIVE_ME_MS_NOW(), from, fn));
  83. }
  84. LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
  85. const char* paramName, const char* paramValue)
  86. {
  87. MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\")\n",
  88. GIVE_ME_MS_NOW(), from, fn,
  89. paramName, paramValue));
  90. }
  91. LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
  92. const char* paramName, const void* paramValue)
  93. {
  94. MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%p\")\n",
  95. GIVE_ME_MS_NOW(), from, fn,
  96. paramName, paramValue));
  97. }
  98. LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
  99. const char* paramName, uint32_t paramValue)
  100. {
  101. MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%d\")\n",
  102. GIVE_ME_MS_NOW(), from, fn,
  103. paramName, paramValue));
  104. }
  105. };
  106. class LogMessage {
  107. public:
  108. LogMessage(mozilla::LogModule* aLog, void* from, const char* fn,
  109. const char* msg)
  110. {
  111. MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s -- %s\n",
  112. GIVE_ME_MS_NOW(), from, fn, msg));
  113. }
  114. };
  115. #define LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line) id ## line
  116. #define LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, line) \
  117. LOG_SCOPE_APPEND_LINE_NUMBER_PASTE(id, line)
  118. #define LOG_SCOPE_APPEND_LINE_NUMBER(id) \
  119. LOG_SCOPE_APPEND_LINE_NUMBER_EXPAND(id, __LINE__)
  120. #define LOG_SCOPE(l, s) \
  121. LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s)
  122. #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) \
  123. LogScope LOG_SCOPE_APPEND_LINE_NUMBER(LOG_SCOPE_TMP_VAR) (l, this, s, pn, pv)
  124. #define LOG_FUNC(l, s) LogFunc(l, this, s)
  125. #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, this, s, pn, pv)
  126. #define LOG_STATIC_FUNC(l, s) LogFunc(l, nullptr, s)
  127. #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) LogFunc(l, nullptr, s, pn, pv)
  128. #define LOG_MSG(l, s, m) LogMessage(l, this, s, m)
  129. #define LOG_MSG_WITH_PARAM LOG_FUNC_WITH_PARAM
  130. #endif // mozilla_image_ImageLogging_h