shill: Rename MLOG to LOG

Redefine the LOG macro to route messages through MLOG.  Changed
mock_log.cc to actively look for messages with the MemoryLog prefix and
remove it, thus greatly simplifying testing.

BUG=chromium-os:31145
TEST=Builds, unit tests still pass

Change-Id: I458f40048375ac8848f7a009d9a6f6b7f52f6744
Reviewed-on: https://gerrit.chromium.org/gerrit/29942
Commit-Ready: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Tested-by: Christopher Wiley <wiley@chromium.org>
diff --git a/mock_log.cc b/mock_log.cc
index 28fb5a7..3df8ba3 100644
--- a/mock_log.cc
+++ b/mock_log.cc
@@ -6,6 +6,8 @@
 
 #include <string>
 
+#include "shill/memory_log.h"
+
 using std::string;
 
 namespace shill {
@@ -31,14 +33,27 @@
                                       const string &full_message) {
   CHECK(instance_);
 
-  // |full_message| looks like this:
-  //   "[0514/165501:INFO:mock_log_unittest.cc(22)] Some message\n"
+  // |full_message| looks like this if it came through MemoryLog:
+  //   "[0514/165501:INFO:mock_log_unittest.cc(22)] memlog: Some message\n"
   // The user wants to match just the substring "Some message".  Strip off the
-  // extra stuff.  |message_start| is the position where the user's message
-  // begins.
+  // extra stuff.  |message_start| is the position where "memlog: " begins.
+  //
+  // However, if the message did not come through MemoryLog, then it is missing
+  // the "memlog: " prefix.  Try and detect this situation and trim off the
+  // prefix when present.
+  size_t prefix_length = strlen(MemoryLog::kMemoryLogPrefix);
+  if (strncmp(full_message.c_str() + message_start,
+              MemoryLog::kMemoryLogPrefix,
+              prefix_length)) {
+    // No prefix to trim
+    prefix_length = 0;
+  }
+  // Note that the -1 is to remove the trailing return line.
   const string::size_type message_length =
-      full_message.length() - message_start - 1;
-  const string message(full_message, message_start, message_length);
+      full_message.length() - message_start - 1 - prefix_length;
+  const string message(full_message,
+                       message_start + prefix_length,
+                       message_length);
 
   // Call Log.  Because Log is a mock method, this sets in motion the mocking
   // magic.