/thirdparty/breakpad/third_party/glog/src/glog/raw_logging.h.in

http://github.com/tomahawk-player/tomahawk · Autoconf · 185 lines · 116 code · 22 blank · 47 comment · 13 complexity · dd9cde3ea1c23651c81b8240a6d28298 MD5 · raw file

  1. // Copyright (c) 2006, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. //
  30. // Author: Maxim Lifantsev
  31. //
  32. // Thread-safe logging routines that do not allocate any memory or
  33. // acquire any locks, and can therefore be used by low-level memory
  34. // allocation and synchronization code.
  35. #ifndef BASE_RAW_LOGGING_H_
  36. #define BASE_RAW_LOGGING_H_
  37. #include <time.h>
  38. @ac_google_start_namespace@
  39. #include "glog/log_severity.h"
  40. #include "glog/vlog_is_on.h"
  41. // Annoying stuff for windows -- makes sure clients can import these functions
  42. #ifndef GOOGLE_GLOG_DLL_DECL
  43. # if defined(_WIN32) && !defined(__CYGWIN__)
  44. # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
  45. # else
  46. # define GOOGLE_GLOG_DLL_DECL
  47. # endif
  48. #endif
  49. // This is similar to LOG(severity) << format... and VLOG(level) << format..,
  50. // but
  51. // * it is to be used ONLY by low-level modules that can't use normal LOG()
  52. // * it is desiged to be a low-level logger that does not allocate any
  53. // memory and does not need any locks, hence:
  54. // * it logs straight and ONLY to STDERR w/o buffering
  55. // * it uses an explicit format and arguments list
  56. // * it will silently chop off really long message strings
  57. // Usage example:
  58. // RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
  59. // RAW_VLOG(3, "status is %i", status);
  60. // These will print an almost standard log lines like this to stderr only:
  61. // E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
  62. // I0821 211317 file.cc:142] RAW: status is 20
  63. #define RAW_LOG(severity, ...) \
  64. do { \
  65. switch (@ac_google_namespace@::severity) { \
  66. case 0: \
  67. RAW_LOG_INFO(__VA_ARGS__); \
  68. break; \
  69. case 1: \
  70. RAW_LOG_WARNING(__VA_ARGS__); \
  71. break; \
  72. case 2: \
  73. RAW_LOG_ERROR(__VA_ARGS__); \
  74. break; \
  75. case 3: \
  76. RAW_LOG_FATAL(__VA_ARGS__); \
  77. break; \
  78. default: \
  79. break; \
  80. } \
  81. } while (0)
  82. // The following STRIP_LOG testing is performed in the header file so that it's
  83. // possible to completely compile out the logging code and the log messages.
  84. #if STRIP_LOG == 0
  85. #define RAW_VLOG(verboselevel, ...) \
  86. do { \
  87. if (VLOG_IS_ON(verboselevel)) { \
  88. RAW_LOG_INFO(__VA_ARGS__); \
  89. } \
  90. } while (0)
  91. #else
  92. #define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__)
  93. #endif // STRIP_LOG == 0
  94. #if STRIP_LOG == 0
  95. #define RAW_LOG_INFO(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::INFO, \
  96. __FILE__, __LINE__, __VA_ARGS__)
  97. #else
  98. #define RAW_LOG_INFO(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
  99. #endif // STRIP_LOG == 0
  100. #if STRIP_LOG <= 1
  101. #define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::WARNING, \
  102. __FILE__, __LINE__, __VA_ARGS__)
  103. #else
  104. #define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
  105. #endif // STRIP_LOG <= 1
  106. #if STRIP_LOG <= 2
  107. #define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::ERROR, \
  108. __FILE__, __LINE__, __VA_ARGS__)
  109. #else
  110. #define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
  111. #endif // STRIP_LOG <= 2
  112. #if STRIP_LOG <= 3
  113. #define RAW_LOG_FATAL(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::FATAL, \
  114. __FILE__, __LINE__, __VA_ARGS__)
  115. #else
  116. #define RAW_LOG_FATAL(...) \
  117. do { \
  118. @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__); \
  119. exit(1); \
  120. } while (0)
  121. #endif // STRIP_LOG <= 3
  122. // Similar to CHECK(condition) << message,
  123. // but for low-level modules: we use only RAW_LOG that does not allocate memory.
  124. // We do not want to provide args list here to encourage this usage:
  125. // if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
  126. // so that the args are not computed when not needed.
  127. #define RAW_CHECK(condition, message) \
  128. do { \
  129. if (!(condition)) { \
  130. RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
  131. } \
  132. } while (0)
  133. // Debug versions of RAW_LOG and RAW_CHECK
  134. #ifndef NDEBUG
  135. #define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
  136. #define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
  137. #else // NDEBUG
  138. #define RAW_DLOG(severity, ...) \
  139. while (false) \
  140. RAW_LOG(severity, __VA_ARGS__)
  141. #define RAW_DCHECK(condition, message) \
  142. while (false) \
  143. RAW_CHECK(condition, message)
  144. #endif // NDEBUG
  145. // Stub log function used to work around for unused variable warnings when
  146. // building with STRIP_LOG > 0.
  147. static inline void RawLogStub__(int ignored, ...) {
  148. }
  149. // Helper function to implement RAW_LOG and RAW_VLOG
  150. // Logs format... at "severity" level, reporting it
  151. // as called from file:line.
  152. // This does not allocate memory or acquire locks.
  153. GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,
  154. const char* file,
  155. int line,
  156. const char* format, ...)
  157. @ac_cv___attribute___printf_4_5@;
  158. // Hack to propagate time information into this module so that
  159. // this module does not have to directly call localtime_r(),
  160. // which could allocate memory.
  161. GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct tm& t, int usecs);
  162. @ac_google_end_namespace@
  163. #endif // BASE_RAW_LOGGING_H_