< prev index next >

src/share/vm/logging/logTagSet.cpp

Print this page
rev 10979 : 8140594: Various minor code improvements (compiler)


  87   }
  88   return tot_written;
  89 }
  90 
  91 void LogTagSet::write(LogLevelType level, const char* fmt, ...) {
  92   va_list args;
  93   va_start(args, fmt);
  94   vwrite(level, fmt, args);
  95   va_end(args);
  96 }
  97 
  98 const size_t vwrite_buffer_size = 512;
  99 
 100 void LogTagSet::vwrite(LogLevelType level, const char* fmt, va_list args) {
 101   assert(level >= LogLevel::First && level <= LogLevel::Last, "Log level:%d is incorrect", level);
 102   char buf[vwrite_buffer_size];
 103   va_list saved_args;           // For re-format on buf overflow.
 104   va_copy(saved_args, args);
 105   size_t prefix_len = _write_prefix(buf, sizeof(buf));
 106   // Check that string fits in buffer; resize buffer if necessary
 107   int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);





 108   assert(ret >= 0, "Log message buffer issue");
 109   if ((size_t)ret >= sizeof(buf)) {
 110     size_t newbuf_len = prefix_len + ret + 1;
 111     char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
 112     memcpy(newbuf, buf, prefix_len);
 113     ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args);
 114     assert(ret >= 0, "Log message buffer issue");
 115     log(level, newbuf);
 116     FREE_C_HEAP_ARRAY(char, newbuf);
 117   } else {
 118     log(level, buf);
 119   }
 120   va_end(saved_args);
 121 }


  87   }
  88   return tot_written;
  89 }
  90 
  91 void LogTagSet::write(LogLevelType level, const char* fmt, ...) {
  92   va_list args;
  93   va_start(args, fmt);
  94   vwrite(level, fmt, args);
  95   va_end(args);
  96 }
  97 
  98 const size_t vwrite_buffer_size = 512;
  99 
 100 void LogTagSet::vwrite(LogLevelType level, const char* fmt, va_list args) {
 101   assert(level >= LogLevel::First && level <= LogLevel::Last, "Log level:%d is incorrect", level);
 102   char buf[vwrite_buffer_size];
 103   va_list saved_args;           // For re-format on buf overflow.
 104   va_copy(saved_args, args);
 105   size_t prefix_len = _write_prefix(buf, sizeof(buf));
 106   // Check that string fits in buffer; resize buffer if necessary
 107   int ret;
 108   if (prefix_len < vwrite_buffer_size) {
 109     ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
 110   } else {
 111     ret = prefix_len + os::log_vsnprintf(buf, sizeof(buf), fmt, args);
 112   }
 113   assert(ret >= 0, "Log message buffer issue");
 114   if ((size_t)ret >= sizeof(buf)) {
 115     size_t newbuf_len = prefix_len + ret + 1;
 116     char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
 117     prefix_len = _write_prefix(newbuf, newbuf_len);
 118     ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args);
 119     assert(ret >= 0, "Log message buffer issue");
 120     log(level, newbuf);
 121     FREE_C_HEAP_ARRAY(char, newbuf);
 122   } else {
 123     log(level, buf);
 124   }
 125   va_end(saved_args);
 126 }
< prev index next >