120 if (value == SIZE_MAX || value > SIZE_MAX / K) {
121 success = false;
122 break;
123 }
124 _rotate_size = value * K;
125 } else {
126 success = false;
127 break;
128 }
129 pos = comma_pos + 1;
130 } while (comma_pos != NULL);
131
132 os::free(opts);
133 return success;
134 }
135
136 bool LogFileOutput::initialize(const char* options) {
137 if (!configure_rotation(options)) {
138 return false;
139 }
140 _stream = fopen(_file_name, FileOpenMode);
141 if (_stream == NULL) {
142 log_error(logging)("Could not open log file '%s' (%s).\n", _file_name, strerror(errno));
143 return false;
144 }
145 return true;
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();
|
120 if (value == SIZE_MAX || value > SIZE_MAX / K) {
121 success = false;
122 break;
123 }
124 _rotate_size = value * K;
125 } else {
126 success = false;
127 break;
128 }
129 pos = comma_pos + 1;
130 } while (comma_pos != NULL);
131
132 os::free(opts);
133 return success;
134 }
135
136 bool LogFileOutput::initialize(const char* options) {
137 if (!configure_rotation(options)) {
138 return false;
139 }
140
141 // Remove any existing log file in order to replace it (rather than append it)
142 remove(_file_name);
143
144 _stream = fopen(_file_name, FileOpenMode);
145 if (_stream == NULL) {
146 log_error(logging)("Could not open log file '%s' (%s).\n", _file_name, strerror(errno));
147 return false;
148 }
149 return true;
150 }
151
152 int LogFileOutput::write(const LogDecorations& decorations, const char* msg) {
153 if (_stream == NULL) {
154 // An error has occurred with this output, avoid writing to it.
155 return 0;
156 }
157
158 _rotation_semaphore.wait();
159 int written = LogFileStreamOutput::write(decorations, msg);
160 _current_size += written;
161
162 if (should_rotate()) {
163 rotate();
|