< prev index next >

src/share/vm/logging/log.hpp

Print this page




  89 template <LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
  90 class LogImpl;
  91 
  92 // Non-template helper class for implementing write-slowpath in cpp
  93 class LogWriteHelper : AllStatic {
  94  private:
  95 
  96   template <LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
  97   friend class LogImpl;
  98 
  99   ATTRIBUTE_PRINTF(6, 0)
 100   static void write_large(LogTagSet& lts,
 101                           LogLevelType level,
 102                           const char* prefix,
 103                           size_t prefix_len,
 104                           size_t msg_len,
 105                           const char* fmt,
 106                           va_list args);
 107 };
 108 


















 109 template <LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG, LogTagType T3 = LogTag::__NO_TAG,
 110           LogTagType T4 = LogTag::__NO_TAG, LogTagType GuardTag = LogTag::__NO_TAG>
 111 class LogImpl VALUE_OBJ_CLASS_SPEC {
 112  private:
 113   static const size_t LogBufferSize = 512;
 114  public:
 115   // Make sure no more than the maximum number of tags have been given.
 116   // The GuardTag allows this to be detected if/when it happens. If the GuardTag
 117   // is not __NO_TAG, the number of tags given exceeds the maximum allowed.
 118   STATIC_ASSERT(GuardTag == LogTag::__NO_TAG); // Number of logging tags exceeds maximum supported!
 119 
 120   // Empty constructor to avoid warnings on MSVC about unused variables
 121   // when the log instance is only used for static functions.
 122   LogImpl() {
 123   }
 124 
 125   static bool is_level(LogLevelType level) {
 126     return LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().is_level(level);
 127   }
 128 


 165 #define LOG_LEVEL(level, name) ATTRIBUTE_PRINTF(2, 0) \
 166   LogImpl& v##name(const char* fmt, va_list args) { \
 167     vwrite(LogLevel::level, fmt, args); \
 168     return *this; \
 169   } \
 170   LogImpl& name(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3) { \
 171     va_list args; \
 172     va_start(args, fmt); \
 173     vwrite(LogLevel::level, fmt, args); \
 174     va_end(args); \
 175     return *this; \
 176   } \
 177   static bool is_##name() { \
 178     return is_level(LogLevel::level); \
 179   } \
 180   static outputStream* name##_stream() { \
 181     return new logStream(write<LogLevel::level>); \
 182   }
 183   LOG_LEVEL_LIST
 184 #undef LOG_LEVEL


























 185 };
 186 
 187 #endif // SHARE_VM_LOGGING_LOG_HPP


  89 template <LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
  90 class LogImpl;
  91 
  92 // Non-template helper class for implementing write-slowpath in cpp
  93 class LogWriteHelper : AllStatic {
  94  private:
  95 
  96   template <LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
  97   friend class LogImpl;
  98 
  99   ATTRIBUTE_PRINTF(6, 0)
 100   static void write_large(LogTagSet& lts,
 101                           LogLevelType level,
 102                           const char* prefix,
 103                           size_t prefix_len,
 104                           size_t msg_len,
 105                           const char* fmt,
 106                           va_list args);
 107 };
 108 
 109 //
 110 // Log class that embeds both log tags and a log level.
 111 //
 112 // The class provides a way to write the tags and log level once,
 113 // so that redundant specification of tags or levels can be avoided.
 114 //
 115 // Example usage:
 116 //   LogTarget(Debug, gc) out;
 117 //   if (out.is_enabled()) {
 118 //     ...
 119 //     out.print("Worker: %u", i);
 120 //     out.print(" data: %d", x);
 121 //     ...
 122 //     print_stats(out.stream());
 123 //   }
 124 //
 125 #define LogTarget(level, ...) LogTargetImpl<LogLevel::level, LOG_TAGS(__VA_ARGS__)>
 126 
 127 template <LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG, LogTagType T3 = LogTag::__NO_TAG,
 128           LogTagType T4 = LogTag::__NO_TAG, LogTagType GuardTag = LogTag::__NO_TAG>
 129 class LogImpl VALUE_OBJ_CLASS_SPEC {
 130  private:
 131   static const size_t LogBufferSize = 512;
 132  public:
 133   // Make sure no more than the maximum number of tags have been given.
 134   // The GuardTag allows this to be detected if/when it happens. If the GuardTag
 135   // is not __NO_TAG, the number of tags given exceeds the maximum allowed.
 136   STATIC_ASSERT(GuardTag == LogTag::__NO_TAG); // Number of logging tags exceeds maximum supported!
 137 
 138   // Empty constructor to avoid warnings on MSVC about unused variables
 139   // when the log instance is only used for static functions.
 140   LogImpl() {
 141   }
 142 
 143   static bool is_level(LogLevelType level) {
 144     return LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().is_level(level);
 145   }
 146 


 183 #define LOG_LEVEL(level, name) ATTRIBUTE_PRINTF(2, 0) \
 184   LogImpl& v##name(const char* fmt, va_list args) { \
 185     vwrite(LogLevel::level, fmt, args); \
 186     return *this; \
 187   } \
 188   LogImpl& name(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3) { \
 189     va_list args; \
 190     va_start(args, fmt); \
 191     vwrite(LogLevel::level, fmt, args); \
 192     va_end(args); \
 193     return *this; \
 194   } \
 195   static bool is_##name() { \
 196     return is_level(LogLevel::level); \
 197   } \
 198   static outputStream* name##_stream() { \
 199     return new logStream(write<LogLevel::level>); \
 200   }
 201   LOG_LEVEL_LIST
 202 #undef LOG_LEVEL
 203 };
 204 
 205 // Combines logging tags and a logging level.
 206 template <LogLevelType level, LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG,
 207           LogTagType T3 = LogTag::__NO_TAG, LogTagType T4 = LogTag::__NO_TAG, LogTagType GuardTag = LogTag::__NO_TAG>
 208 class LogTargetImpl {
 209 public:
 210   // Empty constructor to avoid warnings on MSVC about unused variables
 211   // when the log instance is only used for static functions.
 212   LogTargetImpl() {
 213   }
 214 
 215   static bool is_enabled() {
 216     return LogImpl<T0, T1, T2, T3, T4, GuardTag>::is_level(level);
 217   }
 218 
 219   static void print(const char* fmt, ...) ATTRIBUTE_PRINTF(1, 2) {
 220     va_list args;
 221     va_start(args, fmt);
 222     LogImpl<T0, T1, T2, T3, T4, GuardTag>::vwrite(level, fmt, args);
 223     va_end(args);
 224   }
 225 
 226   static outputStream* stream() {
 227     return new logStream(&LogImpl<T0, T1, T2, T3, T4, GuardTag>::template write<level>);
 228   }
 229 };
 230 
 231 #endif // SHARE_VM_LOGGING_LOG_HPP
< prev index next >