146 }
147
148 int LogFileOutput::write(const LogDecorations& decorations, const char* msg) {
149 if (_stream == NULL) {
150 // An error has occurred with this output, avoid writing to it.
151 return 0;
152 }
153
154 _rotation_semaphore.wait();
155 int written = LogFileStreamOutput::write(decorations, msg);
156 _current_size += written;
157
158 if (should_rotate()) {
159 rotate();
160 }
161 _rotation_semaphore.signal();
162
163 return written;
164 }
165
166 void LogFileOutput::archive() {
167 assert(_archive_name != NULL && _archive_name_len > 0, "Rotation must be configured before using this function.");
168 int ret = jio_snprintf(_archive_name, _archive_name_len, "%s.%0*u",
169 _file_name, _file_count_max_digits, _current_file);
170 assert(ret >= 0, "Buffer should always be large enough");
171
172 // Attempt to remove possibly existing archived log file before we rename.
173 // Don't care if it fails, we really only care about the rename that follows.
174 remove(_archive_name);
175
176 // Rename the file from ex hotspot.log to hotspot.log.2
177 if (rename(_file_name, _archive_name) == -1) {
178 jio_fprintf(defaultStream::error_stream(), "Could not rename log file '%s' to '%s' (%s).\n",
179 _file_name, _archive_name, os::strerror(errno));
180 }
181 }
182
183 void LogFileOutput::force_rotate() {
184 if (_file_count == 0) {
185 // Rotation not possible
|
146 }
147
148 int LogFileOutput::write(const LogDecorations& decorations, const char* msg) {
149 if (_stream == NULL) {
150 // An error has occurred with this output, avoid writing to it.
151 return 0;
152 }
153
154 _rotation_semaphore.wait();
155 int written = LogFileStreamOutput::write(decorations, msg);
156 _current_size += written;
157
158 if (should_rotate()) {
159 rotate();
160 }
161 _rotation_semaphore.signal();
162
163 return written;
164 }
165
166 int LogFileOutput::write(LogMessageBuffer::Iterator msg_iterator) {
167 if (_stream == NULL) {
168 // An error has occurred with this output, avoid writing to it.
169 return 0;
170 }
171
172 _rotation_semaphore.wait();
173 int written = LogFileStreamOutput::write(msg_iterator);
174 _current_size += written;
175
176 if (should_rotate()) {
177 rotate();
178 }
179 _rotation_semaphore.signal();
180
181 return written;
182 }
183
184 void LogFileOutput::archive() {
185 assert(_archive_name != NULL && _archive_name_len > 0, "Rotation must be configured before using this function.");
186 int ret = jio_snprintf(_archive_name, _archive_name_len, "%s.%0*u",
187 _file_name, _file_count_max_digits, _current_file);
188 assert(ret >= 0, "Buffer should always be large enough");
189
190 // Attempt to remove possibly existing archived log file before we rename.
191 // Don't care if it fails, we really only care about the rename that follows.
192 remove(_archive_name);
193
194 // Rename the file from ex hotspot.log to hotspot.log.2
195 if (rename(_file_name, _archive_name) == -1) {
196 jio_fprintf(defaultStream::error_stream(), "Could not rename log file '%s' to '%s' (%s).\n",
197 _file_name, _archive_name, os::strerror(errno));
198 }
199 }
200
201 void LogFileOutput::force_rotate() {
202 if (_file_count == 0) {
203 // Rotation not possible
|