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 "prims/jvm.h" 30 #include "runtime/arguments.hpp" 31 #include "runtime/os.inline.hpp" 32 #include "utilities/globalDefinitions.hpp" 33 #include "utilities/defaultStream.hpp" 34 35 const char* LogFileOutput::Prefix = "file="; 36 const char* LogFileOutput::FileOpenMode = "a"; 37 const char* LogFileOutput::PidFilenamePlaceholder = "%p"; 38 const char* LogFileOutput::TimestampFilenamePlaceholder = "%t"; 39 const char* LogFileOutput::TimestampFormat = "%Y-%m-%d_%H-%M-%S"; 40 const char* LogFileOutput::FileSizeOptionKey = "filesize"; 41 const char* LogFileOutput::FileCountOptionKey = "filecount"; 42 char LogFileOutput::_pid_str[PidBufferSize]; 43 char LogFileOutput::_vm_start_time_str[StartTimeBufferSize]; 44 45 LogFileOutput::LogFileOutput(const char* name) 46 : LogFileStreamOutput(NULL), _name(os::strdup_check_oom(name, mtLogging)), 47 _file_name(NULL), _archive_name(NULL), _archive_name_len(0), 48 _rotate_size(DefaultFileSize), _file_count(DefaultFileCount), 49 _current_size(0), _current_file(0), _rotation_semaphore(1) { 50 assert(strstr(name, Prefix) == name, "invalid output name '%s': missing prefix: %s", name, Prefix); 51 _file_name = make_file_name(name + strlen(Prefix), _pid_str, _vm_start_time_str); 52 } 53 54 void LogFileOutput::set_file_name_parameters(jlong vm_start_time) { 55 int res = jio_snprintf(_pid_str, sizeof(_pid_str), "%d", os::current_process_id()); 56 assert(res > 0, "PID buffer too small"); 57 58 struct tm local_time; 59 time_t utc_time = vm_start_time / 1000; 60 os::localtime_pd(&utc_time, &local_time); 61 res = (int)strftime(_vm_start_time_str, sizeof(_vm_start_time_str), TimestampFormat, &local_time); | 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 "prims/jvm.h" 30 #include "runtime/arguments.hpp" 31 #include "runtime/os.inline.hpp" 32 #include "utilities/globalDefinitions.hpp" 33 #include "utilities/defaultStream.hpp" 34 35 const char* const LogFileOutput::Prefix = "file="; 36 const char* const LogFileOutput::FileOpenMode = "a"; 37 const char* const LogFileOutput::PidFilenamePlaceholder = "%p"; 38 const char* const LogFileOutput::TimestampFilenamePlaceholder = "%t"; 39 const char* const LogFileOutput::TimestampFormat = "%Y-%m-%d_%H-%M-%S"; 40 const char* const LogFileOutput::FileSizeOptionKey = "filesize"; 41 const char* const LogFileOutput::FileCountOptionKey = "filecount"; 42 char LogFileOutput::_pid_str[PidBufferSize]; 43 char LogFileOutput::_vm_start_time_str[StartTimeBufferSize]; 44 45 LogFileOutput::LogFileOutput(const char* name) 46 : LogFileStreamOutput(NULL), _name(os::strdup_check_oom(name, mtLogging)), 47 _file_name(NULL), _archive_name(NULL), _archive_name_len(0), 48 _rotate_size(DefaultFileSize), _file_count(DefaultFileCount), 49 _current_size(0), _current_file(0), _rotation_semaphore(1) { 50 assert(strstr(name, Prefix) == name, "invalid output name '%s': missing prefix: %s", name, Prefix); 51 _file_name = make_file_name(name + strlen(Prefix), _pid_str, _vm_start_time_str); 52 } 53 54 void LogFileOutput::set_file_name_parameters(jlong vm_start_time) { 55 int res = jio_snprintf(_pid_str, sizeof(_pid_str), "%d", os::current_process_id()); 56 assert(res > 0, "PID buffer too small"); 57 58 struct tm local_time; 59 time_t utc_time = vm_start_time / 1000; 60 os::localtime_pd(&utc_time, &local_time); 61 res = (int)strftime(_vm_start_time_str, sizeof(_vm_start_time_str), TimestampFormat, &local_time); |