< prev index next >
src/share/vm/logging/logMessage.hpp
Print this page
rev 10535 : [mq]: 8145934
rev 10536 : [mq]: 8145934.alternative
rev 10537 : [mq]: 8145934.02
*** 35,54 ****
//
// The interface of LogMessage is very similar to the Log class,
// with printf functions for each level (trace(), debug(), etc).
// The difference is that these functions will append/write to the
// LogMessage, which only buffers the message-parts until the whole
! // message is sent to a log (using Log::write). If TLS has been
! // initialized, messages will be resource allocated, otherwise
! // they will be C heap allocated.
//
// Example usage:
//
// {
// LogMessage(logging) msg;
// if (msg.is_debug()) {
- // ResourceMark rm;
// msg.debug("debug message");
// msg.trace("additional trace information");
// }
// }
//
--- 35,53 ----
//
// The interface of LogMessage is very similar to the Log class,
// with printf functions for each level (trace(), debug(), etc).
// The difference is that these functions will append/write to the
// LogMessage, which only buffers the message-parts until the whole
! // message is sent to a log (using Log::write). Internal buffers
! // are C heap allocated lazily on first write. LogMessages are
! // automatically written when they go out of scope.
//
// Example usage:
//
// {
// LogMessage(logging) msg;
// if (msg.is_debug()) {
// msg.debug("debug message");
// msg.trace("additional trace information");
// }
// }
//
*** 62,81 ****
template <LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG,
LogTagType T3 = LogTag::__NO_TAG, LogTagType T4 = LogTag::__NO_TAG, LogTagType GuardTag = LogTag::__NO_TAG>
class ScopedLogMessage : public LogMessageBuffer {
private:
Log<T0, T1, T2, T3, T4> _log;
public:
! ScopedLogMessage() {
! set_prefix(LogPrefix<T0, T1, T2, T3, T4>::prefix);
}
~ScopedLogMessage() {
! if (_line_count > 0) {
_log.write(*this);
}
}
#define LOG_LEVEL(level, name) \
bool is_##name() const { \
return _log.is_level(LogLevel::level); \
--- 61,99 ----
template <LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG,
LogTagType T3 = LogTag::__NO_TAG, LogTagType T4 = LogTag::__NO_TAG, LogTagType GuardTag = LogTag::__NO_TAG>
class ScopedLogMessage : public LogMessageBuffer {
private:
Log<T0, T1, T2, T3, T4> _log;
+ bool _has_content;
public:
! ScopedLogMessage() : _has_content(false) {
}
~ScopedLogMessage() {
! if (_has_content) {
! flush();
! }
! }
!
! void flush() {
_log.write(*this);
+ reset();
+ }
+
+ void reset() {
+ _has_content = false;
+ LogMessageBuffer::reset();
+ }
+
+ ATTRIBUTE_PRINTF(3, 0)
+ void vwrite(LogLevelType level, const char* fmt, va_list args) {
+ if (!_has_content) {
+ _has_content = true;
+ set_prefix(LogPrefix<T0, T1, T2, T3, T4>::prefix);
}
+ LogMessageBuffer::vwrite(level, fmt, args);
}
#define LOG_LEVEL(level, name) \
bool is_##name() const { \
return _log.is_level(LogLevel::level); \
< prev index next >