--- old/src/share/vm/logging/log.hpp 2016-03-29 15:12:02.614921344 +0200 +++ new/src/share/vm/logging/log.hpp 2016-03-29 15:12:02.490917181 +0200 @@ -106,6 +106,24 @@ va_list args); }; +// +// Log class that embeds both log tags and a log level. +// +// The class provides a way to write the tags and log level once, +// so that redundant specification of tags or levels can be avoided. +// +// Example usage: +// LogTarget(Debug, gc) out; +// if (out.is_enabled()) { +// ... +// out.print("Worker: %u", i); +// out.print(" data: %d", x); +// ... +// print_stats(out.stream()); +// } +// +#define LogTarget(level, ...) LogTargetImpl + template class LogImpl VALUE_OBJ_CLASS_SPEC { @@ -184,4 +202,30 @@ #undef LOG_LEVEL }; +// Combines logging tags and a logging level. +template +class LogTargetImpl { +public: + // Empty constructor to avoid warnings on MSVC about unused variables + // when the log instance is only used for static functions. + LogTargetImpl() { + } + + static bool is_enabled() { + return LogImpl::is_level(level); + } + + static void print(const char* fmt, ...) ATTRIBUTE_PRINTF(1, 2) { + va_list args; + va_start(args, fmt); + LogImpl::vwrite(level, fmt, args); + va_end(args); + } + + static outputStream* stream() { + return new logStream(&LogImpl::template write); + } +}; + #endif // SHARE_VM_LOGGING_LOG_HPP