< prev index next >

src/hotspot/share/logging/logFileStreamOutput.cpp

Print this page

 59 
 60   for (uint i = 0; i < LogDecorators::Count; i++) {
 61     LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(i);
 62     if (!_decorators.is_decorator(decorator)) {
 63       continue;
 64     }
 65 
 66     int written = jio_fprintf(_stream, "[%-*s]",
 67                               _decorator_padding[decorator],
 68                               decorations.decoration(decorator, buf, sizeof(buf)));
 69     if (written <= 0) {
 70       return -1;
 71     } else if (static_cast<size_t>(written - 2) > _decorator_padding[decorator]) {
 72       _decorator_padding[decorator] = written - 2;
 73     }
 74     total_written += written;
 75   }
 76   return total_written;
 77 }
 78 
 79 class FileLocker : public StackObj {
 80 private:
 81   FILE *_file;
 82 
 83 public:
 84   FileLocker(FILE *file) : _file(file) {
 85     os::flockfile(_file);
 86   }
 87 
 88   ~FileLocker() {
 89     os::funlockfile(_file);
 90   }
 91 };
 92 
 93 bool LogFileStreamOutput::flush() {
 94   bool result = true;
 95   if (fflush(_stream) != 0) {
 96     if (!_write_error_is_shown) {
 97       jio_fprintf(defaultStream::error_stream(),
 98                   "Could not flush log: %s (%s (%d))\n", name(), os::strerror(errno), errno);
 99       jio_fprintf(_stream, "\nERROR: Could not flush log (%d)\n", errno);
100       _write_error_is_shown = true;
101     }
102     result = false;
103   }
104   return result;
105 }
106 
107 #define WRITE_LOG_WITH_RESULT_CHECK(op, total)                \
108 {                                                             \
109   int result = op;                                            \
110   if (result < 0) {                                           \
111     if (!_write_error_is_shown) {                             \
112       jio_fprintf(defaultStream::error_stream(),              \

 59 
 60   for (uint i = 0; i < LogDecorators::Count; i++) {
 61     LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(i);
 62     if (!_decorators.is_decorator(decorator)) {
 63       continue;
 64     }
 65 
 66     int written = jio_fprintf(_stream, "[%-*s]",
 67                               _decorator_padding[decorator],
 68                               decorations.decoration(decorator, buf, sizeof(buf)));
 69     if (written <= 0) {
 70       return -1;
 71     } else if (static_cast<size_t>(written - 2) > _decorator_padding[decorator]) {
 72       _decorator_padding[decorator] = written - 2;
 73     }
 74     total_written += written;
 75   }
 76   return total_written;
 77 }
 78 














 79 bool LogFileStreamOutput::flush() {
 80   bool result = true;
 81   if (fflush(_stream) != 0) {
 82     if (!_write_error_is_shown) {
 83       jio_fprintf(defaultStream::error_stream(),
 84                   "Could not flush log: %s (%s (%d))\n", name(), os::strerror(errno), errno);
 85       jio_fprintf(_stream, "\nERROR: Could not flush log (%d)\n", errno);
 86       _write_error_is_shown = true;
 87     }
 88     result = false;
 89   }
 90   return result;
 91 }
 92 
 93 #define WRITE_LOG_WITH_RESULT_CHECK(op, total)                \
 94 {                                                             \
 95   int result = op;                                            \
 96   if (result < 0) {                                           \
 97     if (!_write_error_is_shown) {                             \
 98       jio_fprintf(defaultStream::error_stream(),              \
< prev index next >