--- old/src/share/vm/logging/log.cpp 2016-03-29 15:12:02.386913688 +0200 +++ new/src/share/vm/logging/log.cpp 2016-03-29 15:12:02.230908451 +0200 @@ -93,6 +93,7 @@ Log(logging) _log; public: TestLogSavedConfig(const char* apply_output = NULL, const char* apply_setting = NULL) : _new_output(0) { + ResourceMark rm; _saved_config = os::strdup_check_oom(LogOutput::Stdout->config_string()); bool success = LogConfiguration::parse_log_arguments("stdout", "all=off", NULL, NULL, _log.error_stream()); assert(success, "test unable to turn all off"); @@ -105,6 +106,7 @@ } ~TestLogSavedConfig() { + ResourceMark rm; if (_new_output) { bool success = LogConfiguration::parse_log_arguments(_new_output, "all=off", NULL, NULL, _log.error_stream()); assert(success, "test unable to turn all off"); @@ -154,7 +156,7 @@ ResourceMark rm; Log(logging) log; - TestLogSavedConfig log_cfg("stdout", "logging+test=trace"); + TestLogSavedConfig log_cfg("stdout", "logging*=trace"); LogConfiguration::register_update_listener(&Test_logconfiguration_subscribe_helper); @@ -267,4 +269,55 @@ } } +#define Test_logtarget_string_literal "First line" + + +static void Test_logtarget_on() { + TestLogFile log_file("log_target"); + TestLogSavedConfig tlsc(log_file.name(), "gc=debug"); + + LogTarget(Debug, gc) log; + + assert(log.is_enabled(), "assert"); + + // Log the line and expect it to be available in the output file. + log.print(Test_logtarget_string_literal); + + FILE* fp = fopen(log_file.name(), "r"); + assert(fp, "File read error"); + + char output[256 /* Large enough buffer */]; + if (fgets(output, sizeof(output), fp) != NULL) { + assert(strstr(output, Test_logtarget_string_literal) != NULL, "log line missing"); + } + fclose(fp); +} + +static void Test_logtarget_off() { + TestLogFile log_file("log_target"); + TestLogSavedConfig tlsc(log_file.name(), "gc=info"); + + LogTarget(Debug, gc) log; + + // The log level for gc is info, so this log instance shouldn't be enabled. + assert(!log.is_enabled(), "assert"); + + // Try to log, but expect this to be filtered out. + log.print(Test_logtarget_string_literal); + + FILE* fp = fopen(log_file.name(), "r"); + assert(fp, "File read error"); + + char output[256 /* Large enough buffer */]; + if (fgets(output, sizeof(output), fp) != NULL) { + assert(strstr(output, Test_logtarget_string_literal) == NULL, "log line not missing"); + } + fclose(fp); +} + +void Test_logtarget() { + Test_logtarget_on(); + Test_logtarget_off(); +} + #endif // PRODUCT