Merge
This commit is contained in:
commit
170382e84f
@ -39,6 +39,7 @@
|
||||
|
||||
LogOutput** LogConfiguration::_outputs = NULL;
|
||||
size_t LogConfiguration::_n_outputs = 0;
|
||||
bool LogConfiguration::_post_initialized = false;
|
||||
|
||||
void LogConfiguration::post_initialize() {
|
||||
assert(LogConfiguration_lock != NULL, "Lock must be initialized before post-initialization");
|
||||
@ -51,6 +52,8 @@ void LogConfiguration::post_initialize() {
|
||||
MutexLocker ml(LogConfiguration_lock);
|
||||
describe(log.trace_stream());
|
||||
}
|
||||
|
||||
_post_initialized = true;
|
||||
}
|
||||
|
||||
void LogConfiguration::initialize(jlong vm_start_time) {
|
||||
@ -422,3 +425,12 @@ void LogConfiguration::print_command_line_help(FILE* out) {
|
||||
"\t Turn off all logging, including warnings and errors,\n"
|
||||
"\t and then enable messages tagged with 'rt' using 'trace' level to file 'rttrace.txt'.\n");
|
||||
}
|
||||
|
||||
void LogConfiguration::rotate_all_outputs() {
|
||||
for (size_t idx = 0; idx < _n_outputs; idx++) {
|
||||
if (_outputs[idx]->is_rotatable()) {
|
||||
_outputs[idx]->rotate(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ class LogConfiguration : public AllStatic {
|
||||
private:
|
||||
static LogOutput** _outputs;
|
||||
static size_t _n_outputs;
|
||||
static bool _post_initialized;
|
||||
|
||||
// Create a new output. Returns NULL if failed.
|
||||
static LogOutput* new_output(char* name, const char* options = NULL);
|
||||
@ -94,6 +95,13 @@ class LogConfiguration : public AllStatic {
|
||||
|
||||
// Prints usage help for command line log configuration.
|
||||
static void print_command_line_help(FILE* out);
|
||||
|
||||
static bool is_post_initialized() {
|
||||
return _post_initialized;
|
||||
}
|
||||
|
||||
// Rotates all LogOutput
|
||||
static void rotate_all_outputs();
|
||||
};
|
||||
|
||||
#endif // SHARE_VM_LOGGING_LOGCONFIGURATION_HPP
|
||||
|
@ -35,13 +35,15 @@ LogDiagnosticCommand::LogDiagnosticCommand(outputStream* output, bool heap_alloc
|
||||
_what("what", "Configures what tags to log.", "STRING", false),
|
||||
_decorators("decorators", "Configures which decorators to use. Use 'none' or an empty value to remove all.", "STRING", false),
|
||||
_disable("disable", "Turns off all logging and clears the log configuration.", "BOOLEAN", false),
|
||||
_list("list", "Lists current log configuration.", "BOOLEAN", false) {
|
||||
_list("list", "Lists current log configuration.", "BOOLEAN", false),
|
||||
_rotate("rotate", "Rotates all logs.", "BOOLEAN", false) {
|
||||
_dcmdparser.add_dcmd_option(&_output);
|
||||
_dcmdparser.add_dcmd_option(&_output_options);
|
||||
_dcmdparser.add_dcmd_option(&_what);
|
||||
_dcmdparser.add_dcmd_option(&_decorators);
|
||||
_dcmdparser.add_dcmd_option(&_disable);
|
||||
_dcmdparser.add_dcmd_option(&_list);
|
||||
_dcmdparser.add_dcmd_option(&_rotate);
|
||||
}
|
||||
|
||||
int LogDiagnosticCommand::num_arguments() {
|
||||
@ -86,6 +88,11 @@ void LogDiagnosticCommand::execute(DCmdSource source, TRAPS) {
|
||||
any_command = true;
|
||||
}
|
||||
|
||||
if (_rotate.has_value()) {
|
||||
LogConfiguration::rotate_all_outputs();
|
||||
any_command = true;
|
||||
}
|
||||
|
||||
if (!any_command) {
|
||||
// If no argument was provided, print usage
|
||||
print_help(LogDiagnosticCommand::name());
|
||||
|
@ -43,6 +43,7 @@ class LogDiagnosticCommand : public DCmdWithParser {
|
||||
DCmdArgument<char *> _decorators;
|
||||
DCmdArgument<bool> _disable;
|
||||
DCmdArgument<bool> _list;
|
||||
DCmdArgument<bool> _rotate;
|
||||
|
||||
public:
|
||||
LogDiagnosticCommand(outputStream* output, bool heap_allocated);
|
||||
@ -55,7 +56,7 @@ class LogDiagnosticCommand : public DCmdWithParser {
|
||||
}
|
||||
|
||||
static const char* description() {
|
||||
return "Lists, enables, disables or changes a log output configuration.";
|
||||
return "Lists current log configuration, enables/disables/configures a log output, or rotates all logs.";
|
||||
}
|
||||
|
||||
// Used by SecurityManager. This DCMD requires ManagementPermission = control.
|
||||
|
@ -155,12 +155,7 @@ int LogFileOutput::write(const LogDecorations& decorations, const char* msg) {
|
||||
int written = LogFileStreamOutput::write(decorations, msg);
|
||||
_current_size += written;
|
||||
|
||||
if (should_rotate()) {
|
||||
MutexLockerEx ml(&_rotation_lock, true /* no safepoint check */);
|
||||
if (should_rotate()) {
|
||||
rotate();
|
||||
}
|
||||
}
|
||||
rotate(false);
|
||||
|
||||
return written;
|
||||
}
|
||||
@ -182,7 +177,14 @@ void LogFileOutput::archive() {
|
||||
}
|
||||
}
|
||||
|
||||
void LogFileOutput::rotate() {
|
||||
void LogFileOutput::rotate(bool force) {
|
||||
|
||||
if (!should_rotate(force)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MutexLockerEx ml(&_rotation_lock, true /* no safepoint check */);
|
||||
|
||||
// Archive the current log file
|
||||
archive();
|
||||
|
||||
|
@ -58,13 +58,13 @@ class LogFileOutput : public LogFileStreamOutput {
|
||||
size_t _current_size;
|
||||
|
||||
void archive();
|
||||
void rotate();
|
||||
bool configure_rotation(const char* options);
|
||||
char *make_file_name(const char* file_name, const char* pid_string, const char* timestamp_string);
|
||||
static size_t parse_value(const char* value_str);
|
||||
|
||||
bool should_rotate() const {
|
||||
return _file_count > 0 && _rotate_size > 0 && _current_size >= _rotate_size;
|
||||
bool should_rotate(bool force) {
|
||||
return is_rotatable() &&
|
||||
(force || (_rotate_size > 0 && _current_size >= _rotate_size));
|
||||
}
|
||||
|
||||
public:
|
||||
@ -73,6 +73,12 @@ class LogFileOutput : public LogFileStreamOutput {
|
||||
virtual bool initialize(const char* options);
|
||||
virtual int write(const LogDecorations& decorations, const char* msg);
|
||||
|
||||
virtual bool is_rotatable() {
|
||||
return LogConfiguration::is_post_initialized() && (_file_count > 0);
|
||||
}
|
||||
|
||||
virtual void rotate(bool force);
|
||||
|
||||
virtual const char* name() const {
|
||||
return _name;
|
||||
}
|
||||
|
@ -75,6 +75,14 @@ class LogOutput : public CHeapObj<mtLogging> {
|
||||
virtual const char* name() const = 0;
|
||||
virtual bool initialize(const char* options) = 0;
|
||||
virtual int write(const LogDecorations &decorations, const char* msg) = 0;
|
||||
|
||||
virtual bool is_rotatable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void rotate(bool force) {
|
||||
// Do nothing by default.
|
||||
}
|
||||
};
|
||||
|
||||
#endif // SHARE_VM_LOGGING_LOGOUTPUT_HPP
|
||||
|
Loading…
Reference in New Issue
Block a user