Path: blob/master/src/hotspot/share/logging/logFileOutput.hpp
40930 views
/*1* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/23#ifndef SHARE_LOGGING_LOGFILEOUTPUT_HPP24#define SHARE_LOGGING_LOGFILEOUTPUT_HPP2526#include "logging/logFileStreamOutput.hpp"27#include "runtime/semaphore.hpp"28#include "utilities/globalDefinitions.hpp"2930class LogDecorations;3132// The log file output, with support for file rotation based on a target size.33class LogFileOutput : public LogFileStreamOutput {34private:35static const char* const FileOpenMode;36static const char* const FileCountOptionKey;37static const char* const FileSizeOptionKey;38static const char* const PidFilenamePlaceholder;39static const char* const TimestampFilenamePlaceholder;40static const char* const TimestampFormat;41static const size_t DefaultFileCount = 5;42static const size_t DefaultFileSize = 20 * M;43static const size_t StartTimeBufferSize = 20;44static const size_t PidBufferSize = 21;45static const uint MaxRotationFileCount = 1000;46static char _pid_str[PidBufferSize];47static char _vm_start_time_str[StartTimeBufferSize];4849const char* _name;50char* _file_name;51char* _archive_name;5253uint _current_file;54uint _file_count;55uint _file_count_max_digits;56bool _is_default_file_count;5758size_t _archive_name_len;59size_t _rotate_size;60size_t _current_size;6162// Semaphore used for synchronizing file rotations and writes63Semaphore _rotation_semaphore;6465void archive();66void rotate();67bool parse_options(const char* options, outputStream* errstream);68char *make_file_name(const char* file_name, const char* pid_string, const char* timestamp_string);6970bool should_rotate() {71return _file_count > 0 && _rotate_size > 0 && _current_size >= _rotate_size;72}7374void increment_file_count() {75_current_file++;76if (_current_file == _file_count) {77_current_file = 0;78}79}8081public:82LogFileOutput(const char *name);83virtual ~LogFileOutput();84virtual bool initialize(const char* options, outputStream* errstream);85virtual int write(const LogDecorations& decorations, const char* msg);86virtual int write(LogMessageBuffer::Iterator msg_iterator);87int write_blocking(const LogDecorations& decorations, const char* msg);88virtual void force_rotate();89virtual void describe(outputStream* out);9091virtual const char* name() const {92return _name;93}9495const char* cur_log_file_name();96static const char* const Prefix;97static void set_file_name_parameters(jlong start_time);98};99100#endif // SHARE_LOGGING_LOGFILEOUTPUT_HPP101102103