Merge "misctrl: use libbase combined logging" into main
diff --git a/bootloader_message/misctrl_main.cpp b/bootloader_message/misctrl_main.cpp
index 42b848e..653b62d 100644
--- a/bootloader_message/misctrl_main.cpp
+++ b/bootloader_message/misctrl_main.cpp
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <android-base/logging.h>
 #include <android-base/properties.h>
 #include <bootloader_message/bootloader_message.h>
 #include <log/log.h>
@@ -21,32 +22,16 @@
 
 #include <cstdio>
 
-static void log(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
-static void log(const char* fmt, ...) {
-  va_list va;
-  va_start(va, fmt);
-
-  va_list vb;
-  va_copy(vb, va);
-
-  __android_log_vprint(ANDROID_LOG_ERROR, "misctrl", fmt, va);
-  va_end(va);
-
-  vfprintf(stderr, fmt, vb);
-  fprintf(stderr, "\n");
-  va_end(vb);
-}
-
 static int check_control_message() {
   misc_control_message m;
   std::string err;
   if (!ReadMiscControlMessage(&m, &err)) {
-    log("Could not read misctrl message: %s", err.c_str());
+    LOG(ERROR) << "Could not read misctrl message: " << err.c_str();
     return 1;
   }
 
   if (m.magic != MISC_CONTROL_MAGIC_HEADER || m.version != MISC_CONTROL_MESSAGE_VERSION) {
-    log("misctrl message invalid, resetting it");
+    LOG(WARNING) << "misctrl message invalid, resetting it";
     m = { .version = MISC_CONTROL_MESSAGE_VERSION,
           .magic = MISC_CONTROL_MAGIC_HEADER,
           .misctrl_flags = 0 };
@@ -57,7 +42,7 @@
   const size_t ps = getpagesize();
 
   if (ps != 4096 && ps != 16384) {
-    log("Unrecognized page size: %zu", ps);
+    LOG(ERROR) << "Unrecognized page size: " << ps;
     res = 1;
   }
 
@@ -69,7 +54,7 @@
   res |= android::base::SetProperty("ro.misctrl.16kb_before", before_16kb ? "1" : "0");
 
   if (!WriteMiscControlMessage(m, &err)) {
-    log("Could not write misctrl message: %s", err.c_str());
+    LOG(ERROR) << "Could not write misctrl message: " << err.c_str();
     res |= 1;
   }
 
@@ -81,22 +66,24 @@
   std::string err;
   bool success = CheckReservedSystemSpaceEmpty(&empty, &err);
   if (!success) {
-    log("Could not read reserved space: %s", err.c_str());
+    LOG(ERROR) << "Could not read reserved space: " << err.c_str();
     return 1;
   }
-  log("System reserved space empty? %d.", empty);
+  LOG(INFO) << "System reserved space empty? " << empty;
 
   if (!err.empty()) {
-    constexpr size_t kPrintChunkSize = 256;
-    for (size_t i = 0; i < err.size(); i += kPrintChunkSize) {
-      log("DATA: %s", err.substr(i, kPrintChunkSize).c_str());
-    }
+    LOG(ERROR) << "Reserved misc space being used: " << err;
   }
 
   return empty ? 0 : 1;
 }
 
-int main() {
+int main(int argc, char** argv) {
+  {
+    using namespace android::base;
+    (void)argc;
+    InitLogging(argv, TeeLogger(LogdLogger(), &StderrLogger));
+  }
   int err = 0;
   err |= check_control_message();
   err |= check_reserved_space();