< prev index next >

src/share/vm/logging/log.hpp

Print this page
rev 9824 : [mq]: fixout
rev 9825 : imported patch log_copyright
   1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 103   Log() {
 104   }
 105 
 106   static bool is_level(LogLevelType level) {
 107     return LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().is_level(level);
 108   }
 109 
 110   template <LogLevelType Level>
 111   ATTRIBUTE_PRINTF(1, 2)
 112   static void write(const char* fmt, ...) {
 113     va_list args;
 114     va_start(args, fmt);
 115     vwrite<Level>(fmt, args);
 116     va_end(args);
 117   };
 118 
 119   template <LogLevelType Level>
 120   ATTRIBUTE_PRINTF(1, 0)
 121   static void vwrite(const char* fmt, va_list args) {
 122     char buf[LogBufferSize];


 123     size_t prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(buf, sizeof(buf));
 124     // Check that string fits in buffer; resize buffer if necessary
 125     int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
 126     assert(ret >= 0, "Log message buffer issue");
 127     if ((size_t)ret > sizeof(buf)) {
 128       size_t newbuf_len = prefix_len + ret + 1;
 129       char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
 130       prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(newbuf, newbuf_len);
 131       ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, args);
 132       assert(ret >= 0, "Log message buffer issue");
 133       puts<Level>(newbuf);
 134       FREE_C_HEAP_ARRAY(char, newbuf);
 135     } else {
 136       puts<Level>(buf);
 137     }
 138   }
 139 
 140   template <LogLevelType Level>
 141   static void puts(const char* string) {
 142     LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().log(Level, string);
 143   }
 144 
 145 #define LOG_LEVEL(level, name) ATTRIBUTE_PRINTF(2, 0) \
 146   Log& v##name(const char* fmt, va_list args) { \
 147     vwrite<LogLevel::level>(fmt, args); \
 148     return *this; \
 149   } \
 150   Log& name(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3) { \
 151     va_list args; \
   1 /*
   2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 103   Log() {
 104   }
 105 
 106   static bool is_level(LogLevelType level) {
 107     return LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().is_level(level);
 108   }
 109 
 110   template <LogLevelType Level>
 111   ATTRIBUTE_PRINTF(1, 2)
 112   static void write(const char* fmt, ...) {
 113     va_list args;
 114     va_start(args, fmt);
 115     vwrite<Level>(fmt, args);
 116     va_end(args);
 117   };
 118 
 119   template <LogLevelType Level>
 120   ATTRIBUTE_PRINTF(1, 0)
 121   static void vwrite(const char* fmt, va_list args) {
 122     char buf[LogBufferSize];
 123     va_list saved_args;         // For re-format on buf overflow.
 124     va_copy(saved_args, args);
 125     size_t prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(buf, sizeof(buf));
 126     // Check that string fits in buffer; resize buffer if necessary
 127     int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
 128     assert(ret >= 0, "Log message buffer issue");
 129     if ((size_t)ret >= sizeof(buf)) {
 130       size_t newbuf_len = prefix_len + ret + 1;
 131       char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
 132       prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(newbuf, newbuf_len);
 133       ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args);
 134       assert(ret >= 0, "Log message buffer issue");
 135       puts<Level>(newbuf);
 136       FREE_C_HEAP_ARRAY(char, newbuf);
 137     } else {
 138       puts<Level>(buf);
 139     }
 140   }
 141 
 142   template <LogLevelType Level>
 143   static void puts(const char* string) {
 144     LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().log(Level, string);
 145   }
 146 
 147 #define LOG_LEVEL(level, name) ATTRIBUTE_PRINTF(2, 0) \
 148   Log& v##name(const char* fmt, va_list args) { \
 149     vwrite<LogLevel::level>(fmt, args); \
 150     return *this; \
 151   } \
 152   Log& name(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3) { \
 153     va_list args; \
< prev index next >