Flesh out the logging implementation.
Add PLOG and ensure we have CHECK_STREQ and CHECK_STRNE to go with
the existing non-functional DCHECK_STREQ and DCHECK_STRNE.
This also gives us two different logging implementations, one for
the host that just uses std::cerr, and one for Android that uses
the Android log.
Also bring in the StringPrintf family.
Change-Id: I8e190c2c58f26b22ee76a2a87d447df6eb0fa73b
diff --git a/src/logging_android.cc b/src/logging_android.cc
new file mode 100644
index 0000000..9d97dbb
--- /dev/null
+++ b/src/logging_android.cc
@@ -0,0 +1,33 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+// Author: enh@google.com (Elliott Hughes)
+
+#include "logging.h"
+
+#include <iostream>
+#include <unistd.h>
+
+#include "cutils/log.h"
+
+static const int kLogSeverityToAndroidLogPriority[] = {
+ ANDROID_LOG_INFO, ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL
+};
+
+LogMessage::LogMessage(const char* file, int line, LogSeverity severity, int error)
+: severity_(severity), errno_(error)
+{
+}
+
+LogMessage::~LogMessage() {
+ if (errno_ != -1) {
+ stream() << ": " << strerror(errno);
+ }
+ int priority = kLogSeverityToAndroidLogPriority[severity_];
+ LOG_PRI(priority, LOG_TAG, "%s", buffer_.str().c_str());
+ if (severity_ == FATAL) {
+ abort(); // TODO: dvmAbort
+ }
+}
+
+std::ostream& LogMessage::stream() {
+ return buffer_;
+}