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 *
23 */
24 #ifndef SHARE_VM_LOGGING_LOG_HPP
25 #define SHARE_VM_LOGGING_LOG_HPP
26
27 #include "logging/logLevel.hpp"
28 #include "logging/logPrefix.hpp"
29 #include "logging/logTagSet.hpp"
30 #include "logging/logTag.hpp"
31 #include "memory/allocation.hpp"
32 #include "runtime/os.hpp"
33 #include "utilities/debug.hpp"
34 #include "utilities/ostream.hpp"
35
36 //
37 // Logging macros
38 //
39 // Usage:
40 // log_<level>(<comma separated log tags>)(<printf-style log arguments>);
41 // e.g.
42 // log_debug(logging)("message %d", i);
43 //
44 // Note that these macros will not evaluate the arguments unless the logging is enabled.
45 //
46 #define log_error(...) (!log_is_enabled(Error, __VA_ARGS__)) ? (void)0 : Log<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Error>
47 #define log_warning(...) (!log_is_enabled(Warning, __VA_ARGS__)) ? (void)0 : Log<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Warning>
48 #define log_info(...) (!log_is_enabled(Info, __VA_ARGS__)) ? (void)0 : Log<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Info>
49 #define log_debug(...) (!log_is_enabled(Debug, __VA_ARGS__)) ? (void)0 : Log<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Debug>
50 #define log_trace(...) (!log_is_enabled(Trace, __VA_ARGS__)) ? (void)0 : Log<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Trace>
51
52 // Macros for logging that should be excluded in product builds.
53 // Available for levels Info, Debug and Trace. Includes test macro that
54 // evaluates to false in product builds.
55 #ifndef PRODUCT
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 Log() {
123 }
124
125 static bool is_level(LogLevelType level) {
126 return LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().is_level(level);
127 }
128
129 ATTRIBUTE_PRINTF(2, 3)
130 static void write(LogLevelType level, const char* fmt, ...) {
131 va_list args;
132 va_start(args, fmt);
133 vwrite(level, fmt, args);
134 va_end(args);
135 };
136
137 template <LogLevelType Level>
138 ATTRIBUTE_PRINTF(1, 2)
139 static void write(const char* fmt, ...) {
140 va_list args;
141 va_start(args, fmt);
142 vwrite(Level, fmt, args);
143 va_end(args);
144 };
145
146 ATTRIBUTE_PRINTF(2, 0)
147 static void vwrite(LogLevelType level, const char* fmt, va_list args) {
148 char buf[LogBufferSize];
149 va_list saved_args; // For re-format on buf overflow.
150 va_copy(saved_args, args);
151 size_t prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(buf, sizeof(buf));
152 // Check that string fits in buffer; resize buffer if necessary
153 int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
154 assert(ret >= 0, "Log message buffer issue");
|
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 *
23 */
24 #ifndef SHARE_VM_LOGGING_LOG_HPP
25 #define SHARE_VM_LOGGING_LOG_HPP
26
27 #include "logging/logLevel.hpp"
28 #include "logging/logPrefix.hpp"
29 #include "logging/logTagSet.hpp"
30 #include "logging/logTag.hpp"
31 #include "memory/allocation.hpp"
32 #include "runtime/os.hpp"
33 #include "utilities/debug.hpp"
34 #include "utilities/ostream.hpp"
35
36 class LogMessageBuffer;
37
38 //
39 // Logging macros
40 //
41 // Usage:
42 // log_<level>(<comma separated log tags>)(<printf-style log arguments>);
43 // e.g.
44 // log_debug(logging)("message %d", i);
45 //
46 // Note that these macros will not evaluate the arguments unless the logging is enabled.
47 //
48 #define log_error(...) (!log_is_enabled(Error, __VA_ARGS__)) ? (void)0 : Log<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Error>
49 #define log_warning(...) (!log_is_enabled(Warning, __VA_ARGS__)) ? (void)0 : Log<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Warning>
50 #define log_info(...) (!log_is_enabled(Info, __VA_ARGS__)) ? (void)0 : Log<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Info>
51 #define log_debug(...) (!log_is_enabled(Debug, __VA_ARGS__)) ? (void)0 : Log<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Debug>
52 #define log_trace(...) (!log_is_enabled(Trace, __VA_ARGS__)) ? (void)0 : Log<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Trace>
53
54 // Macros for logging that should be excluded in product builds.
55 // Available for levels Info, Debug and Trace. Includes test macro that
56 // evaluates to false in product builds.
57 #ifndef PRODUCT
117 // Make sure no more than the maximum number of tags have been given.
118 // The GuardTag allows this to be detected if/when it happens. If the GuardTag
119 // is not __NO_TAG, the number of tags given exceeds the maximum allowed.
120 STATIC_ASSERT(GuardTag == LogTag::__NO_TAG); // Number of logging tags exceeds maximum supported!
121
122 // Empty constructor to avoid warnings on MSVC about unused variables
123 // when the log instance is only used for static functions.
124 Log() {
125 }
126
127 static bool is_level(LogLevelType level) {
128 return LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().is_level(level);
129 }
130
131 ATTRIBUTE_PRINTF(2, 3)
132 static void write(LogLevelType level, const char* fmt, ...) {
133 va_list args;
134 va_start(args, fmt);
135 vwrite(level, fmt, args);
136 va_end(args);
137 };
138
139 static void write(const LogMessageBuffer& msg) {
140 LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().log(msg);
141 };
142
143 template <LogLevelType Level>
144 ATTRIBUTE_PRINTF(1, 2)
145 static void write(const char* fmt, ...) {
146 va_list args;
147 va_start(args, fmt);
148 vwrite(Level, fmt, args);
149 va_end(args);
150 };
151
152 ATTRIBUTE_PRINTF(2, 0)
153 static void vwrite(LogLevelType level, const char* fmt, va_list args) {
154 char buf[LogBufferSize];
155 va_list saved_args; // For re-format on buf overflow.
156 va_copy(saved_args, args);
157 size_t prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(buf, sizeof(buf));
158 // Check that string fits in buffer; resize buffer if necessary
159 int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
160 assert(ret >= 0, "Log message buffer issue");
|