< prev index next >

src/share/vm/logging/logFileOutput.cpp

Print this page
rev 11857 : [mq]: 8157948


  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 }
  50 
  51 void LogFileOutput::set_file_name_parameters(jlong vm_start_time) {
  52   int res = jio_snprintf(_pid_str, sizeof(_pid_str), "%d", os::current_process_id());
  53   assert(res > 0, "PID buffer too small");
  54 
  55   struct tm local_time;
  56   time_t utc_time = vm_start_time / 1000;
  57   os::localtime_pd(&utc_time, &local_time);
  58   res = (int)strftime(_vm_start_time_str, sizeof(_vm_start_time_str), TimestampFormat, &local_time);
  59   assert(res > 0, "VM start time buffer too small.");
  60 }
  61 
  62 LogFileOutput::~LogFileOutput() {
  63   if (_stream != NULL) {
  64     if (fclose(_stream) != 0) {
  65       jio_fprintf(defaultStream::error_stream(), "Could not close log file '%s' (%s).\n",
  66                   _file_name, os::strerror(errno));
  67     }
  68   }




  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   assert(strstr(name, "file=") == name, "invalid output name '%s': missing prefix", name);
  49   _file_name = make_file_name(name + strlen("file="), _pid_str, _vm_start_time_str);
  50 }
  51 
  52 void LogFileOutput::set_file_name_parameters(jlong vm_start_time) {
  53   int res = jio_snprintf(_pid_str, sizeof(_pid_str), "%d", os::current_process_id());
  54   assert(res > 0, "PID buffer too small");
  55 
  56   struct tm local_time;
  57   time_t utc_time = vm_start_time / 1000;
  58   os::localtime_pd(&utc_time, &local_time);
  59   res = (int)strftime(_vm_start_time_str, sizeof(_vm_start_time_str), TimestampFormat, &local_time);
  60   assert(res > 0, "VM start time buffer too small.");
  61 }
  62 
  63 LogFileOutput::~LogFileOutput() {
  64   if (_stream != NULL) {
  65     if (fclose(_stream) != 0) {
  66       jio_fprintf(defaultStream::error_stream(), "Could not close log file '%s' (%s).\n",
  67                   _file_name, os::strerror(errno));
  68     }
  69   }


< prev index next >