< prev index next >
src/share/vm/logging/log.cpp
Print this page
@@ -91,10 +91,11 @@
char* _saved_config;
char* _new_output;
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");
if (apply_output) {
@@ -103,10 +104,11 @@
assert(success, "test unable to apply test log configuration");
}
}
~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");
os::free(_new_output);
}
@@ -152,11 +154,11 @@
void Test_logconfiguration_subscribe() {
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);
LogConfiguration::parse_log_arguments("stdout", "logging=trace", NULL, NULL, log.error_stream());
assert(Test_logconfiguration_subscribe_triggered == 1, "subscription not triggered (1)");
@@ -265,6 +267,57 @@
}
}
}
}
+#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
< prev index next >