This commit is contained in:
Marcus Larsson 2015-12-04 20:04:59 +00:00
commit 170382e84f
7 changed files with 56 additions and 12 deletions

View File

@ -39,6 +39,7 @@
LogOutput** LogConfiguration::_outputs = NULL; LogOutput** LogConfiguration::_outputs = NULL;
size_t LogConfiguration::_n_outputs = 0; size_t LogConfiguration::_n_outputs = 0;
bool LogConfiguration::_post_initialized = false;
void LogConfiguration::post_initialize() { void LogConfiguration::post_initialize() {
assert(LogConfiguration_lock != NULL, "Lock must be initialized before post-initialization"); assert(LogConfiguration_lock != NULL, "Lock must be initialized before post-initialization");
@ -51,6 +52,8 @@ void LogConfiguration::post_initialize() {
MutexLocker ml(LogConfiguration_lock); MutexLocker ml(LogConfiguration_lock);
describe(log.trace_stream()); describe(log.trace_stream());
} }
_post_initialized = true;
} }
void LogConfiguration::initialize(jlong vm_start_time) { 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 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"); "\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);
}
}
}

View File

@ -40,6 +40,7 @@ class LogConfiguration : public AllStatic {
private: private:
static LogOutput** _outputs; static LogOutput** _outputs;
static size_t _n_outputs; static size_t _n_outputs;
static bool _post_initialized;
// Create a new output. Returns NULL if failed. // Create a new output. Returns NULL if failed.
static LogOutput* new_output(char* name, const char* options = NULL); 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. // Prints usage help for command line log configuration.
static void print_command_line_help(FILE* out); 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 #endif // SHARE_VM_LOGGING_LOGCONFIGURATION_HPP

View File

@ -35,13 +35,15 @@ LogDiagnosticCommand::LogDiagnosticCommand(outputStream* output, bool heap_alloc
_what("what", "Configures what tags to log.", "STRING", false), _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), _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), _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);
_dcmdparser.add_dcmd_option(&_output_options); _dcmdparser.add_dcmd_option(&_output_options);
_dcmdparser.add_dcmd_option(&_what); _dcmdparser.add_dcmd_option(&_what);
_dcmdparser.add_dcmd_option(&_decorators); _dcmdparser.add_dcmd_option(&_decorators);
_dcmdparser.add_dcmd_option(&_disable); _dcmdparser.add_dcmd_option(&_disable);
_dcmdparser.add_dcmd_option(&_list); _dcmdparser.add_dcmd_option(&_list);
_dcmdparser.add_dcmd_option(&_rotate);
} }
int LogDiagnosticCommand::num_arguments() { int LogDiagnosticCommand::num_arguments() {
@ -86,6 +88,11 @@ void LogDiagnosticCommand::execute(DCmdSource source, TRAPS) {
any_command = true; any_command = true;
} }
if (_rotate.has_value()) {
LogConfiguration::rotate_all_outputs();
any_command = true;
}
if (!any_command) { if (!any_command) {
// If no argument was provided, print usage // If no argument was provided, print usage
print_help(LogDiagnosticCommand::name()); print_help(LogDiagnosticCommand::name());

View File

@ -43,6 +43,7 @@ class LogDiagnosticCommand : public DCmdWithParser {
DCmdArgument<char *> _decorators; DCmdArgument<char *> _decorators;
DCmdArgument<bool> _disable; DCmdArgument<bool> _disable;
DCmdArgument<bool> _list; DCmdArgument<bool> _list;
DCmdArgument<bool> _rotate;
public: public:
LogDiagnosticCommand(outputStream* output, bool heap_allocated); LogDiagnosticCommand(outputStream* output, bool heap_allocated);
@ -55,7 +56,7 @@ class LogDiagnosticCommand : public DCmdWithParser {
} }
static const char* description() { 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. // Used by SecurityManager. This DCMD requires ManagementPermission = control.

View File

@ -155,12 +155,7 @@ int LogFileOutput::write(const LogDecorations& decorations, const char* msg) {
int written = LogFileStreamOutput::write(decorations, msg); int written = LogFileStreamOutput::write(decorations, msg);
_current_size += written; _current_size += written;
if (should_rotate()) { rotate(false);
MutexLockerEx ml(&_rotation_lock, true /* no safepoint check */);
if (should_rotate()) {
rotate();
}
}
return written; 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 the current log file
archive(); archive();

View File

@ -58,13 +58,13 @@ class LogFileOutput : public LogFileStreamOutput {
size_t _current_size; size_t _current_size;
void archive(); void archive();
void rotate();
bool configure_rotation(const char* options); bool configure_rotation(const char* options);
char *make_file_name(const char* file_name, const char* pid_string, const char* timestamp_string); 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); static size_t parse_value(const char* value_str);
bool should_rotate() const { bool should_rotate(bool force) {
return _file_count > 0 && _rotate_size > 0 && _current_size >= _rotate_size; return is_rotatable() &&
(force || (_rotate_size > 0 && _current_size >= _rotate_size));
} }
public: public:
@ -73,6 +73,12 @@ class LogFileOutput : public LogFileStreamOutput {
virtual bool initialize(const char* options); virtual bool initialize(const char* options);
virtual int write(const LogDecorations& decorations, const char* msg); 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 { virtual const char* name() const {
return _name; return _name;
} }

View File

@ -75,6 +75,14 @@ class LogOutput : public CHeapObj<mtLogging> {
virtual const char* name() const = 0; virtual const char* name() const = 0;
virtual bool initialize(const char* options) = 0; virtual bool initialize(const char* options) = 0;
virtual int write(const LogDecorations &decorations, const char* msg) = 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 #endif // SHARE_VM_LOGGING_LOGOUTPUT_HPP