< prev index next >
src/share/vm/logging/logFileStreamOutput.cpp
Print this page
rev 10661 : [mq]: 8145934
rev 10662 : imported patch 8145934.alternative
@@ -23,40 +23,77 @@
*/
#include "precompiled.hpp"
#include "logging/logDecorators.hpp"
#include "logging/logDecorations.hpp"
#include "logging/logFileStreamOutput.hpp"
+#include "logging/logMessageBuffer.hpp"
#include "memory/allocation.inline.hpp"
LogStdoutOutput LogStdoutOutput::_instance;
LogStderrOutput LogStderrOutput::_instance;
-int LogFileStreamOutput::write(const LogDecorations& decorations, const char* msg) {
- char decoration_buf[LogDecorations::DecorationsBufferSize];
- char* position = decoration_buf;
+int LogFileStreamOutput::write_decorations(char* buffer,
+ size_t buffer_length,
+ const LogDecorations& decorations) {
int total_written = 0;
+ char* position = buffer;
for (uint i = 0; i < LogDecorators::Count; i++) {
LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(i);
if (!_decorators.is_decorator(decorator)) {
continue;
}
- int written = jio_snprintf(position, sizeof(decoration_buf) - total_written, "[%-*s]",
- _decorator_padding[decorator],
- decorations.decoration(decorator));
+
+ int written = jio_snprintf(position, buffer_length - total_written, "[%-*s]",
+ _decorator_padding[decorator], decorations.decoration(decorator));
if (written <= 0) {
return -1;
} else if (static_cast<size_t>(written - 2) > _decorator_padding[decorator]) {
_decorator_padding[decorator] = written - 2;
}
position += written;
total_written += written;
}
+ return total_written;
+}
- if (total_written == 0) {
- total_written = jio_fprintf(_stream, "%s\n", msg);
+int LogFileStreamOutput::write(const LogDecorations& decorations, const char* msg) {
+ const bool use_decorations = !_decorators.is_empty();
+
+ int written;
+ if (use_decorations) {
+ char decoration_buf[LogDecorations::DecorationsBufferSize];
+ write_decorations(decoration_buf, sizeof(decoration_buf), decorations);
+ written = jio_fprintf(_stream, "%s %s\n", decoration_buf, msg);
} else {
- total_written = jio_fprintf(_stream, "%s %s\n", decoration_buf, msg);
+ written = jio_fprintf(_stream, "%s\n", msg);
}
fflush(_stream);
- return total_written;
+
+ return written;
+}
+
+int LogFileStreamOutput::write(LogMessageBuffer::Iterator msg_iterator) {
+ const bool use_decorations = !_decorators.is_empty();
+ char decoration_buf[LogDecorations::DecorationsBufferSize];
+
+ int written = 0;
+ os::flockfile(_stream);
+ LogLevelType previous_level = LogLevel::Invalid;
+ for (; !msg_iterator.is_at_end(); msg_iterator++) {
+ if (use_decorations) {
+ const LogDecorations& decorations = msg_iterator.decorations();
+ // Write decorators the first time, and re-write them if the level changed.
+ if (written == 0 || decorations.level() != previous_level) {
+ write_decorations(decoration_buf, sizeof(decoration_buf), decorations);
+ previous_level = decorations.level();
+ }
+ written += jio_fprintf(_stream, "%s %s\n", decoration_buf, msg_iterator.message());
+ } else {
+ written += jio_fprintf(_stream, "%s\n", msg_iterator.message());
+ }
+ }
+ fflush(_stream);
+ os::funlockfile(_stream);
+
+ return written;
}
< prev index next >