Fix run-test on host.
Change-Id: I44ebb4cdc2f5966be51a063e3c7256ab3016c404
diff --git a/src/logging.h b/src/logging.h
index 7c04777..c1ea3ab 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -262,6 +262,15 @@
bool startup;
bool third_party_jni; // Enabled with "-verbose:third-party-jni".
bool threads;
+ std::ostream* logging_stream;
+
+ void SetLoggingStream(std::ostream* new_logging_stream) {
+ DCHECK(new_logging_stream->good());
+ if (logging_stream != NULL) {
+ delete logging_stream;
+ }
+ logging_stream = new_logging_stream;
+ }
};
extern LogVerbosity gLogVerbosity;
diff --git a/src/logging_linux.cc b/src/logging_linux.cc
index e781a00..4e7c796 100644
--- a/src/logging_linux.cc
+++ b/src/logging_linux.cc
@@ -34,9 +34,11 @@
}
void LogMessage::LogLine(const char* message) {
- std::cerr << "VDIWEFF"[data_->severity] << ' '
- << StringPrintf("%5d %5d", getpid(), ::art::GetTid()) << ' '
- << data_->file << ':' << data_->line_number << "] " << message << std::endl;
+ std::ostream &out =
+ (gLogVerbosity.logging_stream == NULL ? std::cerr : *gLogVerbosity.logging_stream);
+ out << "VDIWEFF"[data_->severity] << ' '
+ << StringPrintf("%5d %5d", getpid(), ::art::GetTid()) << ' '
+ << data_->file << ':' << data_->line_number << "] " << message << std::endl;
}
} // namespace art
diff --git a/src/runtime.cc b/src/runtime.cc
index 12f7c8b..014ce6b 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -22,6 +22,7 @@
#include <cstdlib>
#include <limits>
#include <vector>
+#include <fstream>
#include "class_linker.h"
#include "class_loader.h"
@@ -421,6 +422,15 @@
gLogVerbosity.third_party_jni = true;
} else if (verbose_options[i] == "threads") {
gLogVerbosity.threads = true;
+ } else if (StartsWith(verbose_options[i], "log-to=")) {
+ std::string log_file_name(verbose_options[i].substr(strlen("log-to=")));
+ std::ofstream* log_file = new std::ofstream(log_file_name.c_str());
+ if (log_file->is_open() && log_file->good()) {
+ gLogVerbosity.SetLoggingStream(log_file);
+ } else {
+ LOG(ERROR) << "Fail to open log file: \"" << log_file_name << "\","
+ << " use default logging stream.";
+ }
} else {
LOG(WARNING) << "Ignoring unknown -verbose option: " << verbose_options[i];
}
diff --git a/src/runtime_support.cc b/src/runtime_support.cc
index 0a1cf8f..d6efe1d 100644
--- a/src/runtime_support.cc
+++ b/src/runtime_support.cc
@@ -221,8 +221,8 @@
return result;
}
-static inline std::string ClassNameFromIndex(const Method* method, uint32_t ref,
- verifier::VerifyErrorRefType ref_type, bool access) {
+static std::string ClassNameFromIndex(const Method* method, uint32_t ref,
+ verifier::VerifyErrorRefType ref_type, bool access) {
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
const DexFile& dex_file = class_linker->FindDexFile(method->GetDeclaringClass()->GetDexCache());