< prev index next >

src/hotspot/share/logging/logFileStreamOutput.cpp

Print this page

 76 
 77   for (uint i = 0; i < LogDecorators::Count; i++) {
 78     LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(i);
 79     if (!_decorators.is_decorator(decorator)) {
 80       continue;
 81     }
 82 
 83     int written = jio_fprintf(_stream, "[%-*s]",
 84                               _decorator_padding[decorator],
 85                               decorations.decoration(decorator, buf, sizeof(buf)));
 86     if (written <= 0) {
 87       return -1;
 88     } else if (static_cast<size_t>(written - 2) > _decorator_padding[decorator]) {
 89       _decorator_padding[decorator] = written - 2;
 90     }
 91     total_written += written;
 92   }
 93   return total_written;
 94 }
 95 
 96 class FileLocker : public StackObj {
 97 private:
 98   FILE *_file;
 99 
100 public:
101   FileLocker(FILE *file) : _file(file) {
102     os::flockfile(_file);
103   }
104 
105   ~FileLocker() {
106     os::funlockfile(_file);
107   }
108 };
109 
110 bool LogFileStreamOutput::flush() {
111   bool result = true;
112   if (fflush(_stream) != 0) {
113     if (!_write_error_is_shown) {
114       jio_fprintf(defaultStream::error_stream(),
115                   "Could not flush log: %s (%s (%d))\n", name(), os::strerror(errno), errno);
116       jio_fprintf(_stream, "\nERROR: Could not flush log (%d)\n", errno);
117       _write_error_is_shown = true;
118     }
119     result = false;
120   }
121   return result;
122 }
123 
124 #define WRITE_LOG_WITH_RESULT_CHECK(op, total)                \
125 {                                                             \
126   int result = op;                                            \
127   if (result < 0) {                                           \
128     if (!_write_error_is_shown) {                             \
129       jio_fprintf(defaultStream::error_stream(),              \

 76 
 77   for (uint i = 0; i < LogDecorators::Count; i++) {
 78     LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(i);
 79     if (!_decorators.is_decorator(decorator)) {
 80       continue;
 81     }
 82 
 83     int written = jio_fprintf(_stream, "[%-*s]",
 84                               _decorator_padding[decorator],
 85                               decorations.decoration(decorator, buf, sizeof(buf)));
 86     if (written <= 0) {
 87       return -1;
 88     } else if (static_cast<size_t>(written - 2) > _decorator_padding[decorator]) {
 89       _decorator_padding[decorator] = written - 2;
 90     }
 91     total_written += written;
 92   }
 93   return total_written;
 94 }
 95 














 96 bool LogFileStreamOutput::flush() {
 97   bool result = true;
 98   if (fflush(_stream) != 0) {
 99     if (!_write_error_is_shown) {
100       jio_fprintf(defaultStream::error_stream(),
101                   "Could not flush log: %s (%s (%d))\n", name(), os::strerror(errno), errno);
102       jio_fprintf(_stream, "\nERROR: Could not flush log (%d)\n", errno);
103       _write_error_is_shown = true;
104     }
105     result = false;
106   }
107   return result;
108 }
109 
110 #define WRITE_LOG_WITH_RESULT_CHECK(op, total)                \
111 {                                                             \
112   int result = op;                                            \
113   if (result < 0) {                                           \
114     if (!_write_error_is_shown) {                             \
115       jio_fprintf(defaultStream::error_stream(),              \
< prev index next >