< prev index next >

src/share/vm/logging/logFileOutput.cpp

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 #include "precompiled.hpp"
  25 #include "logging/log.hpp"
  26 #include "logging/logConfiguration.hpp"
  27 #include "logging/logFileOutput.hpp"
  28 #include "memory/allocation.inline.hpp"

  29 #include "runtime/os.inline.hpp"
  30 #include "utilities/globalDefinitions.hpp"
  31 #include "utilities/defaultStream.hpp"
  32 
  33 const char* LogFileOutput::FileOpenMode = "a";
  34 const char* LogFileOutput::PidFilenamePlaceholder = "%p";
  35 const char* LogFileOutput::TimestampFilenamePlaceholder = "%t";
  36 const char* LogFileOutput::TimestampFormat = "%Y-%m-%d_%H-%M-%S";
  37 const char* LogFileOutput::FileSizeOptionKey = "filesize";
  38 const char* LogFileOutput::FileCountOptionKey = "filecount";
  39 char        LogFileOutput::_pid_str[PidBufferSize];
  40 char        LogFileOutput::_vm_start_time_str[StartTimeBufferSize];
  41 
  42 LogFileOutput::LogFileOutput(const char* name)
  43     : LogFileStreamOutput(NULL), _name(os::strdup_check_oom(name, mtLogging)),
  44       _file_name(NULL), _archive_name(NULL), _archive_name_len(0),
  45       _rotate_size(DefaultFileSize), _file_count(DefaultFileCount),
  46       _current_size(0), _current_file(0), _rotation_semaphore(1) {
  47   _file_name = make_file_name(name, _pid_str, _vm_start_time_str);
  48 }


 170     char* equals_pos = strchr(pos, '=');
 171     if (equals_pos == NULL) {
 172       success = false;
 173       break;
 174     }
 175     char* key = pos;
 176     char* value_str = equals_pos + 1;
 177     *equals_pos = '\0';
 178 
 179     if (strcmp(FileCountOptionKey, key) == 0) {
 180       size_t value = parse_value(value_str);
 181       if (value > MaxRotationFileCount) {
 182         errstream->print_cr("Invalid option: %s must be in range [0, %u]",
 183                             FileCountOptionKey,
 184                             MaxRotationFileCount);
 185         success = false;
 186         break;
 187       }
 188       _file_count = static_cast<uint>(value);
 189     } else if (strcmp(FileSizeOptionKey, key) == 0) {
 190       size_t value = parse_value(value_str);
 191       if (value == SIZE_MAX || value > SIZE_MAX / K) {



 192         errstream->print_cr("Invalid option: %s must be in range [0, "
 193                             SIZE_FORMAT "]", FileSizeOptionKey, SIZE_MAX / K);
 194         success = false;
 195         break;
 196       }
 197       _rotate_size = value * K;
 198     } else {
 199       errstream->print_cr("Invalid option '%s' for log file output.", key);
 200       success = false;
 201       break;
 202     }
 203     pos = comma_pos + 1;
 204   } while (comma_pos != NULL);
 205 
 206   os::free(opts);
 207   return success;
 208 }
 209 
 210 bool LogFileOutput::initialize(const char* options, outputStream* errstream) {
 211   if (!parse_options(options, errstream)) {
 212     return false;
 213   }
 214 
 215   if (_file_count > 0) {
 216     // compute digits with filecount - 1 since numbers will start from 0
 217     _file_count_max_digits = number_of_digits(_file_count - 1);




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 #include "precompiled.hpp"
  25 #include "logging/log.hpp"
  26 #include "logging/logConfiguration.hpp"
  27 #include "logging/logFileOutput.hpp"
  28 #include "memory/allocation.inline.hpp"
  29 #include "runtime/arguments.hpp"
  30 #include "runtime/os.inline.hpp"
  31 #include "utilities/globalDefinitions.hpp"
  32 #include "utilities/defaultStream.hpp"
  33 
  34 const char* LogFileOutput::FileOpenMode = "a";
  35 const char* LogFileOutput::PidFilenamePlaceholder = "%p";
  36 const char* LogFileOutput::TimestampFilenamePlaceholder = "%t";
  37 const char* LogFileOutput::TimestampFormat = "%Y-%m-%d_%H-%M-%S";
  38 const char* LogFileOutput::FileSizeOptionKey = "filesize";
  39 const char* LogFileOutput::FileCountOptionKey = "filecount";
  40 char        LogFileOutput::_pid_str[PidBufferSize];
  41 char        LogFileOutput::_vm_start_time_str[StartTimeBufferSize];
  42 
  43 LogFileOutput::LogFileOutput(const char* name)
  44     : LogFileStreamOutput(NULL), _name(os::strdup_check_oom(name, mtLogging)),
  45       _file_name(NULL), _archive_name(NULL), _archive_name_len(0),
  46       _rotate_size(DefaultFileSize), _file_count(DefaultFileCount),
  47       _current_size(0), _current_file(0), _rotation_semaphore(1) {
  48   _file_name = make_file_name(name, _pid_str, _vm_start_time_str);
  49 }


 171     char* equals_pos = strchr(pos, '=');
 172     if (equals_pos == NULL) {
 173       success = false;
 174       break;
 175     }
 176     char* key = pos;
 177     char* value_str = equals_pos + 1;
 178     *equals_pos = '\0';
 179 
 180     if (strcmp(FileCountOptionKey, key) == 0) {
 181       size_t value = parse_value(value_str);
 182       if (value > MaxRotationFileCount) {
 183         errstream->print_cr("Invalid option: %s must be in range [0, %u]",
 184                             FileCountOptionKey,
 185                             MaxRotationFileCount);
 186         success = false;
 187         break;
 188       }
 189       _file_count = static_cast<uint>(value);
 190     } else if (strcmp(FileSizeOptionKey, key) == 0) {
 191       julong value;
 192       success = Arguments::atojulong(value_str, &value);
 193       if (!success) {
 194         break;
 195       } else if (value > SIZE_MAX) {
 196         errstream->print_cr("Invalid option: %s must be in range [0, "
 197                             SIZE_FORMAT "]", FileSizeOptionKey, SIZE_MAX);
 198         success = false;
 199         break;
 200       }
 201       _rotate_size = value;
 202     } else {
 203       errstream->print_cr("Invalid option '%s' for log file output.", key);
 204       success = false;
 205       break;
 206     }
 207     pos = comma_pos + 1;
 208   } while (comma_pos != NULL);
 209 
 210   os::free(opts);
 211   return success;
 212 }
 213 
 214 bool LogFileOutput::initialize(const char* options, outputStream* errstream) {
 215   if (!parse_options(options, errstream)) {
 216     return false;
 217   }
 218 
 219   if (_file_count > 0) {
 220     // compute digits with filecount - 1 since numbers will start from 0
 221     _file_count_max_digits = number_of_digits(_file_count - 1);


< prev index next >