Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/hotspot/share/logging/logConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,9 @@ void LogConfiguration::disable_logging() {
notify_update_listeners();
}

void LogConfiguration::configure_stdout(LogLevelType level, int exact_match, ...) {
LogSelectionList LogConfiguration::create_selection_list(LogLevelType level, int exact_match, va_list ap) {
size_t i;
va_list ap;
LogTagType tags[LogTag::MaxTags];
va_start(ap, exact_match);
for (i = 0; i < LogTag::MaxTags; i++) {
LogTagType tag = static_cast<LogTagType>(va_arg(ap, int));
tags[i] = tag;
Expand All @@ -351,12 +349,32 @@ void LogConfiguration::configure_stdout(LogLevelType level, int exact_match, ...
}
assert(i < LogTag::MaxTags || static_cast<LogTagType>(va_arg(ap, int)) == LogTag::__NO_TAG,
"Too many tags specified! Can only have up to %zu tags in a tag set.", LogTag::MaxTags);
va_end(ap);

LogSelection selection(tags, !exact_match, level);
assert(selection.tag_sets_selected() > 0,
"configure_stdout() called with invalid/non-existing log selection");
LogSelectionList list(selection);
"create_selection_list() called with invalid/non-existing log selection");
return LogSelectionList(selection);
}

void LogConfiguration::disable_tags(int exact_match, ...) {
va_list ap;
va_start(ap, exact_match);
LogSelectionList list = create_selection_list(LogLevel::Off, exact_match, ap);
va_end(ap);

// Apply configuration to all outputs, with the same decorators as before.
ConfigurationLock cl;
for (size_t i = 0; i < _n_outputs; i++) {
configure_output(i, list, _outputs[i]->decorators());
}
notify_update_listeners();
}

void LogConfiguration::configure_stdout(LogLevelType level, int exact_match, ...) {
va_list ap;
va_start(ap, exact_match);
LogSelectionList list = create_selection_list(level, exact_match, ap);
va_end(ap);

// Apply configuration to stdout (output #0), with the same decorators as before.
ConfigurationLock cl;
Expand Down
9 changes: 9 additions & 0 deletions src/hotspot/share/logging/logConfiguration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class LogConfiguration : public AllStatic {
static void describe_available(outputStream* out);
static void describe_current_configuration(outputStream* out);

// Create a LogSelectionList given a level and a set of tags
static LogSelectionList create_selection_list(LogLevelType level, int exact_match, va_list ap);

public:
// Initialization and finalization of log configuration, to be run at vm startup and shutdown respectively.
Expand All @@ -109,6 +111,13 @@ class LogConfiguration : public AllStatic {
// Disable all logging, equivalent to -Xlog:disable.
static void disable_logging();

// Disables logging on all outputs for the given tags.
// If exact_match is true, only tagsets with precisely the specified tags will be disabled
// (exact_match=false is the same as "-Xlog:<tags>*=off", and exact_match=true is "-Xlog:<tags>=off").
// Tags should be specified using the LOG_TAGS macro, e.g.
// LogConfiguration::disable_tags(<true/false>, LOG_TAGS(<tags>));
static void disable_tags(int exact_match, ...);

// Configures logging on stdout for the given tags and level combination.
// Intended for mappings between -XX: flags and Unified Logging configuration.
// If exact_match is true, only tagsets with precisely the specified tags will be configured
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/runtime/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3800,7 +3800,8 @@ jint Arguments::apply_ergo() {
if (log_is_enabled(Info, perf, class, link)) {
if (!UsePerfData) {
warning("Disabling -Xlog:perf+class+link since UsePerfData is turned off.");
LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(perf, class, link));
LogConfiguration::disable_tags(false, LOG_TAGS(perf, class, link));
assert(!log_is_enabled(Info, perf, class, link), "sanity");
}
}

Expand Down
26 changes: 26 additions & 0 deletions test/hotspot/gtest/logging/test_logConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ TEST_VM_F(LogConfigurationTest, disable_output) {
}
}

TEST_VM_F(LogConfigurationTest, disable_tags) {
set_log_config("stdout", "logging*=info");
set_log_config(TestLogFileName, "logging*=info");

EXPECT_TRUE(log_is_enabled(Info, logging, gc));
LogConfiguration::disable_tags(true, LOG_TAGS(logging, gc));
EXPECT_FALSE(log_is_enabled(Info, logging, gc));
EXPECT_TRUE(log_is_enabled(Info, logging));

set_log_config("stdout", "logging*=info");
set_log_config(TestLogFileName, "logging*=info");

EXPECT_TRUE(log_is_enabled(Info, logging));
LogConfiguration::disable_tags(true, LOG_TAGS(logging));
EXPECT_TRUE(log_is_enabled(Info, logging, gc));
EXPECT_FALSE(log_is_enabled(Info, logging));

set_log_config("stdout", "logging*=info");
set_log_config(TestLogFileName, "logging*=info");

EXPECT_TRUE(log_is_enabled(Info, logging));
LogConfiguration::disable_tags(false, LOG_TAGS(logging));
EXPECT_FALSE(log_is_enabled(Info, logging, gc));
EXPECT_FALSE(log_is_enabled(Info, logging));
}

// Test reconfiguration of the selected decorators for an output
TEST_VM_F(LogConfigurationTest, reconfigure_decorators) {
// Configure stderr with all decorators
Expand Down