Switch recovery to libbase logging

Clean up the recovery image and switch to libbase logging.

Bug: 28191554
Change-Id: Icd999c3cc832f0639f204b5c36cea8afe303ad35
Merged-In: Icd999c3cc832f0639f204b5c36cea8afe303ad35
diff --git a/Android.mk b/Android.mk
index 41eff4e..76e99b6 100644
--- a/Android.mk
+++ b/Android.mk
@@ -145,7 +145,7 @@
     asn1_decoder.cpp \
     verifier.cpp \
     ui.cpp
-LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto
+LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto libbase
 include $(BUILD_STATIC_LIBRARY)
 
 include $(LOCAL_PATH)/minui/Android.mk \
diff --git a/applypatch/Android.mk b/applypatch/Android.mk
index 604787e..0fc6e36 100644
--- a/applypatch/Android.mk
+++ b/applypatch/Android.mk
@@ -80,7 +80,7 @@
     libminzip \
     libcrypto \
     libbz
-LOCAL_SHARED_LIBRARIES += libz libcutils libc
+LOCAL_SHARED_LIBRARIES += libbase libz libcutils libc
 include $(BUILD_EXECUTABLE)
 
 # imgdiff (host static executable)
diff --git a/bootloader.cpp b/bootloader.cpp
index 783f56e..dad0bab 100644
--- a/bootloader.cpp
+++ b/bootloader.cpp
@@ -25,37 +25,38 @@
 
 #include <fs_mgr.h>
 
-#include "bootloader.h"
-#include "common.h"
-#include "roots.h"
+#include <android-base/logging.h>
 #include <android-base/unique_fd.h>
 
+#include "bootloader.h"
+#include "roots.h"
+
 static int get_bootloader_message_block(bootloader_message* out, const Volume* v);
 static int set_bootloader_message_block(const bootloader_message* in, const Volume* v);
 
 int get_bootloader_message(bootloader_message* out) {
     Volume* v = volume_for_path("/misc");
     if (v == nullptr) {
-        LOGE("Cannot load volume /misc!\n");
+        LOG(ERROR) << "Cannot load volume /misc!";
         return -1;
     }
     if (strcmp(v->fs_type, "emmc") == 0) {
         return get_bootloader_message_block(out, v);
     }
-    LOGE("unknown misc partition fs_type \"%s\"\n", v->fs_type);
+    LOG(ERROR) << "unknown misc partition fs_type \"" << v->fs_type << "\"";
     return -1;
 }
 
 int set_bootloader_message(const bootloader_message* in) {
     Volume* v = volume_for_path("/misc");
     if (v == nullptr) {
-        LOGE("Cannot load volume /misc!\n");
+        LOG(ERROR) << "Cannot load volume /misc!";
         return -1;
     }
     if (strcmp(v->fs_type, "emmc") == 0) {
         return set_bootloader_message_block(in, v);
     }
-    LOGE("unknown misc partition fs_type \"%s\"\n", v->fs_type);
+    LOG(ERROR) << "unknown misc partition fs_type \"" << v->fs_type << "\"";
     return -1;
 }
 
@@ -86,17 +87,17 @@
     wait_for_device(v->blk_device);
     FILE* f = fopen(v->blk_device, "rb");
     if (f == nullptr) {
-        LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno));
+        PLOG(ERROR) << "failed to open \"" << v->blk_device << "\"";
         return -1;
     }
     bootloader_message temp;
     int count = fread(&temp, sizeof(temp), 1, f);
     if (count != 1) {
-        LOGE("failed to read \"%s\": %s\n", v->blk_device, strerror(errno));
+        PLOG(ERROR) << "failed to read \"" << v->blk_device << "\"";
         return -1;
     }
     if (fclose(f) != 0) {
-        LOGE("failed to close \"%s\": %s\n", v->blk_device, strerror(errno));
+        PLOG(ERROR) << "failed to close \"" << v->blk_device << "\"";
         return -1;
     }
     memcpy(out, &temp, sizeof(temp));
@@ -108,7 +109,7 @@
     wait_for_device(v->blk_device);
     android::base::unique_fd fd(open(v->blk_device, O_WRONLY | O_SYNC));
     if (fd == -1) {
-        LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno));
+        PLOG(ERROR) << "failed to open \"" << v->blk_device << "\"";
         return -1;
     }
 
@@ -118,15 +119,15 @@
     while (written < total) {
         ssize_t wrote = TEMP_FAILURE_RETRY(write(fd, start + written, total - written));
         if (wrote == -1) {
-            LOGE("failed to write %" PRId64 " bytes: %s\n",
-                 static_cast<off64_t>(written), strerror(errno));
+            PLOG(ERROR) << "failed to write " << total << " bytes, " << written
+                        << " bytes written";
             return -1;
         }
         written += wrote;
     }
 
     if (fsync(fd) == -1) {
-        LOGE("failed to fsync \"%s\": %s\n", v->blk_device, strerror(errno));
+        PLOG(ERROR) << "failed to fsync \"" << v->blk_device << "\"";
         return -1;
     }
     return 0;
diff --git a/common.h b/common.h
index de8b409..a948fb1 100644
--- a/common.h
+++ b/common.h
@@ -21,18 +21,6 @@
 #include <stdio.h>
 #include <stdarg.h>
 
-#define LOGE(...) ui_print("E:" __VA_ARGS__)
-#define LOGW(...) fprintf(stdout, "W:" __VA_ARGS__)
-#define LOGI(...) fprintf(stdout, "I:" __VA_ARGS__)
-
-#if 0
-#define LOGV(...) fprintf(stdout, "V:" __VA_ARGS__)
-#define LOGD(...) fprintf(stdout, "D:" __VA_ARGS__)
-#else
-#define LOGV(...) do {} while (0)
-#define LOGD(...) do {} while (0)
-#endif
-
 #define STRINGIFY(x) #x
 #define EXPAND(x) STRINGIFY(x)
 
diff --git a/install.cpp b/install.cpp
index 10a90a0..92a62db 100644
--- a/install.cpp
+++ b/install.cpp
@@ -30,6 +30,7 @@
 #include <android-base/parseint.h>
 #include <android-base/stringprintf.h>
 #include <android-base/strings.h>
+#include <android-base/logging.h>
 
 #include "common.h"
 #include "error_code.h"
@@ -64,7 +65,7 @@
         }
     }
 
-    LOGE("Failed to parse build number in %s.\n", str.c_str());
+    LOG(ERROR) << "Failed to parse build number in " << str;
     return -1;
 }
 
@@ -72,13 +73,13 @@
 static void read_source_target_build(ZipArchive* zip, std::vector<std::string>& log_buffer) {
     const ZipEntry* meta_entry = mzFindZipEntry(zip, METADATA_PATH);
     if (meta_entry == nullptr) {
-        LOGE("Failed to find %s in update package.\n", METADATA_PATH);
+        LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package";
         return;
     }
 
     std::string meta_data(meta_entry->uncompLen, '\0');
     if (!mzReadZipEntry(zip, meta_entry, &meta_data[0], meta_entry->uncompLen)) {
-        LOGE("Failed to read metadata in update package.\n");
+        LOG(ERROR) << "Failed to read metadata in update package";
         return;
     }
 
@@ -122,8 +123,8 @@
     unlink(binary);
     int fd = creat(binary, 0755);
     if (fd < 0) {
+        PLOG(ERROR) << "Can't make " << binary;
         mzCloseZipArchive(zip);
-        LOGE("Can't make %s\n", binary);
         return INSTALL_ERROR;
     }
     bool ok = mzExtractZipEntryToFile(zip, binary_entry, fd);
@@ -131,7 +132,7 @@
     mzCloseZipArchive(zip);
 
     if (!ok) {
-        LOGE("Can't copy %s\n", ASSUMED_UPDATE_BINARY_NAME);
+        LOG(ERROR) << "Can't copy " << ASSUMED_UPDATE_BINARY_NAME;
         return INSTALL_ERROR;
     }
 
@@ -252,7 +253,7 @@
             // last_install later.
             log_buffer.push_back(std::string(strtok(NULL, "\n")));
         } else {
-            LOGE("unknown command [%s]\n", command);
+            LOG(ERROR) << "unknown command [" << command << "]";
         }
     }
     fclose(from_child);
@@ -263,7 +264,7 @@
         return INSTALL_RETRY;
     }
     if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
-        LOGE("Error in %s\n(Status %d)\n", path, WEXITSTATUS(status));
+        LOG(ERROR) << "Error in " << path << " (Status " << WEXITSTATUS(status) << ")";
         return INSTALL_ERROR;
     }
 
@@ -279,7 +280,7 @@
     // Give verification half the progress bar...
     ui->SetProgressType(RecoveryUI::DETERMINATE);
     ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME);
-    LOGI("Update location: %s\n", path);
+    LOG(INFO) << "Update location: " << path;
 
     // Map the update package into memory.
     ui->Print("Opening update package...\n");
@@ -294,27 +295,28 @@
 
     MemMapping map;
     if (sysMapFile(path, &map) != 0) {
-        LOGE("failed to map file\n");
+        LOG(ERROR) << "failed to map file";
         return INSTALL_CORRUPT;
     }
 
     // Load keys.
     std::vector<Certificate> loadedKeys;
     if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) {
-        LOGE("Failed to load keys\n");
+        LOG(ERROR) << "Failed to load keys";
         sysReleaseMap(&map);
         return INSTALL_CORRUPT;
     }
-    LOGI("%zu key(s) loaded from %s\n", loadedKeys.size(), PUBLIC_KEYS_FILE);
+    LOG(INFO) << loadedKeys.size() << " key(s) loaded from " << PUBLIC_KEYS_FILE;
 
     // Verify package.
     ui->Print("Verifying update package...\n");
+
     auto t0 = std::chrono::system_clock::now();
     int err = verify_file(map.addr, map.length, loadedKeys);
     std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0;
     ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err);
     if (err != VERIFY_SUCCESS) {
-        LOGE("signature verification failed\n");
+        LOG(ERROR) << "signature verification failed";
         log_buffer.push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure));
 
         sysReleaseMap(&map);
@@ -325,7 +327,7 @@
     ZipArchive zip;
     err = mzOpenZipArchive(map.addr, map.length, &zip);
     if (err != 0) {
-        LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad");
+        LOG(ERROR) << "Can't open " << path;
         log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure));
 
         sysReleaseMap(&map);
@@ -359,12 +361,12 @@
         fputs(path, install_log);
         fputc('\n', install_log);
     } else {
-        LOGE("failed to open last_install: %s\n", strerror(errno));
+        PLOG(ERROR) << "failed to open last_install";
     }
     int result;
     std::vector<std::string> log_buffer;
     if (setup_install_mounts() != 0) {
-        LOGE("failed to set up expected mounts for install; aborting\n");
+        LOG(ERROR) << "failed to set up expected mounts for install; aborting";
         result = INSTALL_ERROR;
     } else {
         result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count);
diff --git a/minzip/Android.mk b/minzip/Android.mk
index 3d36fd6..6dbfee9 100644
--- a/minzip/Android.mk
+++ b/minzip/Android.mk
@@ -2,17 +2,17 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
-	Hash.c \
-	SysUtil.c \
+	Hash.cpp \
+	SysUtil.cpp \
 	DirUtil.cpp \
 	Inlines.c \
-	Zip.c
+	Zip.cpp
 
 LOCAL_C_INCLUDES := \
 	external/zlib \
 	external/safe-iop/include
 
-LOCAL_STATIC_LIBRARIES := libselinux
+LOCAL_STATIC_LIBRARIES := libselinux libbase
 
 LOCAL_MODULE := libminzip
 
diff --git a/minzip/Hash.c b/minzip/Hash.cpp
similarity index 96%
rename from minzip/Hash.c
rename to minzip/Hash.cpp
index 49bcb31..ac08935 100644
--- a/minzip/Hash.c
+++ b/minzip/Hash.cpp
@@ -8,8 +8,8 @@
 #include <stdlib.h>
 #include <assert.h>
 
-#define LOG_TAG "minzip"
-#include "Log.h"
+#include <android-base/logging.h>
+
 #include "Hash.h"
 
 /* table load factor, i.e. how full can it get before we resize */
@@ -220,8 +220,7 @@
             {
                 if (!resizeHash(pHashTable, pHashTable->tableSize * 2)) {
                     /* don't really have a way to indicate failure */
-                    LOGE("Dalvik hash resize failure\n");
-                    abort();
+                    LOG(FATAL) << "Hash resize failure";
                 }
                 /* note "pEntry" is now invalid */
             }
@@ -373,7 +372,7 @@
         totalProbe += count;
     }
 
-    LOGV("Probe: min=%d max=%d, total=%d in %d (%d), avg=%.3f\n",
-        minProbe, maxProbe, totalProbe, numEntries, pHashTable->tableSize,
-        (float) totalProbe / (float) numEntries);
+    LOG(VERBOSE) << "Probe: min=" << minProbe << ", max=" << maxProbe << ", total="
+                 << totalProbe <<" in " << numEntries << " (" << pHashTable->tableSize
+                 << "), avg=" << (float) totalProbe / (float) numEntries;
 }
diff --git a/minzip/Log.h b/minzip/Log.h
deleted file mode 100644
index 36e62f5..0000000
--- a/minzip/Log.h
+++ /dev/null
@@ -1,207 +0,0 @@
-//
-// Copyright 2005 The Android Open Source Project
-//
-// C/C++ logging functions.  See the logging documentation for API details.
-//
-// We'd like these to be available from C code (in case we import some from
-// somewhere), so this has a C interface.
-//
-// The output will be correct when the log file is shared between multiple
-// threads and/or multiple processes so long as the operating system
-// supports O_APPEND.  These calls have mutex-protected data structures
-// and so are NOT reentrant.  Do not use LOG in a signal handler.
-//
-#ifndef _MINZIP_LOG_H
-#define _MINZIP_LOG_H
-
-#include <stdio.h>
-
-// ---------------------------------------------------------------------
-
-/*
- * Normally we strip LOGV (VERBOSE messages) from release builds.
- * You can modify this (for example with "#define LOG_NDEBUG 0"
- * at the top of your source file) to change that behavior.
- */
-#ifndef LOG_NDEBUG
-#ifdef NDEBUG
-#define LOG_NDEBUG 1
-#else
-#define LOG_NDEBUG 0
-#endif
-#endif
-
-/*
- * This is the local tag used for the following simplified
- * logging macros.  You can change this preprocessor definition
- * before using the other macros to change the tag.
- */
-#ifndef LOG_TAG
-#define LOG_TAG NULL
-#endif
-
-// ---------------------------------------------------------------------
-
-/*
- * Simplified macro to send a verbose log message using the current LOG_TAG.
- */
-#ifndef LOGV
-#if LOG_NDEBUG
-#define LOGV(...)   ((void)0)
-#else
-#define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
-#endif
-#endif
-
-#define CONDITION(cond)     (__builtin_expect((cond)!=0, 0))
-
-#ifndef LOGV_IF
-#if LOG_NDEBUG
-#define LOGV_IF(cond, ...)   ((void)0)
-#else
-#define LOGV_IF(cond, ...) \
-    ( (CONDITION(cond)) \
-    ? ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
-    : (void)0 )
-#endif
-#endif
-
-#define LOGVV LOGV
-#define LOGVV_IF LOGV_IF
-
-/*
- * Simplified macro to send a debug log message using the current LOG_TAG.
- */
-#ifndef LOGD
-#define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef LOGD_IF
-#define LOGD_IF(cond, ...) \
-    ( (CONDITION(cond)) \
-    ? ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
-    : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an info log message using the current LOG_TAG.
- */
-#ifndef LOGI
-#define LOGI(...) ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef LOGI_IF
-#define LOGI_IF(cond, ...) \
-    ( (CONDITION(cond)) \
-    ? ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
-    : (void)0 )
-#endif
-
-/*
- * Simplified macro to send a warning log message using the current LOG_TAG.
- */
-#ifndef LOGW
-#define LOGW(...) ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef LOGW_IF
-#define LOGW_IF(cond, ...) \
-    ( (CONDITION(cond)) \
-    ? ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
-    : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an error log message using the current LOG_TAG.
- */
-#ifndef LOGE
-#define LOGE(...) ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef LOGE_IF
-#define LOGE_IF(cond, ...) \
-    ( (CONDITION(cond)) \
-    ? ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
-    : (void)0 )
-#endif
-
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * verbose priority.
- */
-#ifndef IF_LOGV
-#if LOG_NDEBUG
-#define IF_LOGV() if (false)
-#else
-#define IF_LOGV() IF_LOG(LOG_VERBOSE, LOG_TAG)
-#endif
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * debug priority.
- */
-#ifndef IF_LOGD
-#define IF_LOGD() IF_LOG(LOG_DEBUG, LOG_TAG)
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * info priority.
- */
-#ifndef IF_LOGI
-#define IF_LOGI() IF_LOG(LOG_INFO, LOG_TAG)
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * warn priority.
- */
-#ifndef IF_LOGW
-#define IF_LOGW() IF_LOG(LOG_WARN, LOG_TAG)
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * error priority.
- */
-#ifndef IF_LOGE
-#define IF_LOGE() IF_LOG(LOG_ERROR, LOG_TAG)
-#endif
-
-// ---------------------------------------------------------------------
-
-/*
- * Basic log message macro.
- *
- * Example:
- *  LOG(LOG_WARN, NULL, "Failed with error %d", errno);
- *
- * The second argument may be NULL or "" to indicate the "global" tag.
- *
- * Non-gcc probably won't have __FUNCTION__.  It's not vital.  gcc also
- * offers __PRETTY_FUNCTION__, which is rather more than we need.
- */
-#ifndef LOG
-#define LOG(priority, tag, ...) \
-    LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
-#endif
-
-/*
- * Log macro that allows you to specify a number for the priority.
- */
-#ifndef LOG_PRI
-#define LOG_PRI(priority, tag, ...) \
-    printf(tag ": " __VA_ARGS__)
-#endif
-
-/*
- * Conditional given a desired logging priority and tag.
- */
-#ifndef IF_LOG
-#define IF_LOG(priority, tag) \
-    if (1)
-#endif
-
-#endif // _MINZIP_LOG_H
diff --git a/minzip/SysUtil.c b/minzip/SysUtil.cpp
similarity index 68%
rename from minzip/SysUtil.c
rename to minzip/SysUtil.cpp
index e7dd17b..2936c5c 100644
--- a/minzip/SysUtil.c
+++ b/minzip/SysUtil.cpp
@@ -16,8 +16,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#define LOG_TAG "sysutil"
-#include "Log.h"
+#include <android-base/logging.h>
+
 #include "SysUtil.h"
 
 static bool sysMapFD(int fd, MemMapping* pMap) {
@@ -25,22 +25,22 @@
 
     struct stat sb;
     if (fstat(fd, &sb) == -1) {
-        LOGE("fstat(%d) failed: %s\n", fd, strerror(errno));
+        PLOG(ERROR) << "fstat(" << fd << ") failed";
         return false;
     }
 
     void* memPtr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
     if (memPtr == MAP_FAILED) {
-        LOGE("mmap(%d, R, PRIVATE, %d, 0) failed: %s\n", (int) sb.st_size, fd, strerror(errno));
+        PLOG(ERROR) << "mmap(" << sb.st_size << ", R, PRIVATE, " << fd << ", 0) failed";
         return false;
     }
 
-    pMap->addr = memPtr;
+    pMap->addr = reinterpret_cast<unsigned char*>(memPtr);
     pMap->length = sb.st_size;
     pMap->range_count = 1;
-    pMap->ranges = malloc(sizeof(MappedRange));
+    pMap->ranges = reinterpret_cast<MappedRange*>(malloc(sizeof(MappedRange)));
     if (pMap->ranges == NULL) {
-        LOGE("malloc failed: %s\n", strerror(errno));
+        PLOG(ERROR) << "malloc failed";
         munmap(memPtr, sb.st_size);
         return false;
     }
@@ -60,7 +60,7 @@
     unsigned int i;
 
     if (fgets(block_dev, sizeof(block_dev), mapf) == NULL) {
-        LOGE("failed to read block device from header\n");
+        PLOG(ERROR) << "failed to read block device from header";
         return -1;
     }
     for (i = 0; i < sizeof(block_dev); ++i) {
@@ -71,37 +71,37 @@
     }
 
     if (fscanf(mapf, "%zu %u\n%u\n", &size, &blksize, &range_count) != 3) {
-        LOGE("failed to parse block map header\n");
+        LOG(ERROR) << "failed to parse block map header";
         return -1;
     }
     if (blksize != 0) {
         blocks = ((size-1) / blksize) + 1;
     }
     if (size == 0 || blksize == 0 || blocks > SIZE_MAX / blksize || range_count == 0) {
-        LOGE("invalid data in block map file: size %zu, blksize %u, range_count %u\n",
-             size, blksize, range_count);
+        LOG(ERROR) << "invalid data in block map file: size " << size << ", blksize " << blksize
+                   << ", range_count " << range_count;
         return -1;
     }
 
     pMap->range_count = range_count;
-    pMap->ranges = calloc(range_count, sizeof(MappedRange));
+    pMap->ranges = reinterpret_cast<MappedRange*>(calloc(range_count, sizeof(MappedRange)));
     if (pMap->ranges == NULL) {
-        LOGE("calloc(%u, %zu) failed: %s\n", range_count, sizeof(MappedRange), strerror(errno));
+        PLOG(ERROR) << "calloc(" << range_count << ", " << sizeof(MappedRange) << ") failed";
         return -1;
     }
 
     // Reserve enough contiguous address space for the whole file.
-    unsigned char* reserve;
-    reserve = mmap64(NULL, blocks * blksize, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0);
+    unsigned char* reserve = reinterpret_cast<unsigned char*>(mmap64(NULL, blocks * blksize,
+            PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0));
     if (reserve == MAP_FAILED) {
-        LOGE("failed to reserve address space: %s\n", strerror(errno));
+        PLOG(ERROR) << "failed to reserve address space";
         free(pMap->ranges);
         return -1;
     }
 
     int fd = open(block_dev, O_RDONLY);
     if (fd < 0) {
-        LOGE("failed to open block device %s: %s\n", block_dev, strerror(errno));
+        PLOG(ERROR) << "failed to open block device " << block_dev;
         munmap(reserve, blocks * blksize);
         free(pMap->ranges);
         return -1;
@@ -113,20 +113,20 @@
     for (i = 0; i < range_count; ++i) {
         size_t start, end;
         if (fscanf(mapf, "%zu %zu\n", &start, &end) != 2) {
-            LOGE("failed to parse range %d in block map\n", i);
+            LOG(ERROR) << "failed to parse range " << i << " in block map";
             success = false;
             break;
         }
         size_t length = (end - start) * blksize;
         if (end <= start || (end - start) > SIZE_MAX / blksize || length > remaining_size) {
-          LOGE("unexpected range in block map: %zu %zu\n", start, end);
+          LOG(ERROR) << "unexpected range in block map: " << start << " " << end;
           success = false;
           break;
         }
 
         void* addr = mmap64(next, length, PROT_READ, MAP_PRIVATE | MAP_FIXED, fd, ((off64_t)start)*blksize);
         if (addr == MAP_FAILED) {
-            LOGE("failed to map block %d: %s\n", i, strerror(errno));
+            PLOG(ERROR) << "failed to map block " << i;
             success = false;
             break;
         }
@@ -137,7 +137,7 @@
         remaining_size -= length;
     }
     if (success && remaining_size != 0) {
-      LOGE("ranges in block map are invalid: remaining_size = %zu\n", remaining_size);
+      LOG(ERROR) << "ranges in block map are invalid: remaining_size = " << remaining_size;
       success = false;
     }
     if (!success) {
@@ -151,7 +151,7 @@
     pMap->addr = reserve;
     pMap->length = size;
 
-    LOGI("mmapped %d ranges\n", range_count);
+    LOG(INFO) << "mmapped " << range_count << " ranges";
 
     return 0;
 }
@@ -164,12 +164,12 @@
         // A map of blocks
         FILE* mapf = fopen(fn+1, "r");
         if (mapf == NULL) {
-            LOGE("Unable to open '%s': %s\n", fn+1, strerror(errno));
+            PLOG(ERROR) << "Unable to open '" << (fn+1) << "'";
             return -1;
         }
 
         if (sysMapBlockFile(mapf, pMap) != 0) {
-            LOGE("Map of '%s' failed\n", fn);
+            LOG(ERROR) << "Map of '" << fn << "' failed";
             fclose(mapf);
             return -1;
         }
@@ -179,12 +179,12 @@
         // This is a regular file.
         int fd = open(fn, O_RDONLY);
         if (fd == -1) {
-            LOGE("Unable to open '%s': %s\n", fn, strerror(errno));
+            PLOG(ERROR) << "Unable to open '" << fn << "'";
             return -1;
         }
 
         if (!sysMapFD(fd, pMap)) {
-            LOGE("Map of '%s' failed\n", fn);
+            LOG(ERROR) << "Map of '" << fn << "' failed";
             close(fd);
             return -1;
         }
@@ -202,8 +202,8 @@
     int i;
     for (i = 0; i < pMap->range_count; ++i) {
         if (munmap(pMap->ranges[i].addr, pMap->ranges[i].length) < 0) {
-            LOGE("munmap(%p, %d) failed: %s\n",
-                 pMap->ranges[i].addr, (int)pMap->ranges[i].length, strerror(errno));
+            PLOG(ERROR) << "munmap(" << pMap->ranges[i].addr << ", " << pMap->ranges[i].length
+                        << ") failed";
         }
     }
     free(pMap->ranges);
diff --git a/minzip/Zip.c b/minzip/Zip.cpp
similarity index 86%
rename from minzip/Zip.c
rename to minzip/Zip.cpp
index d557daa..b887b84 100644
--- a/minzip/Zip.c
+++ b/minzip/Zip.cpp
@@ -14,18 +14,18 @@
 #include <sys/stat.h>   // for S_ISLNK()
 #include <unistd.h>
 
-#define LOG_TAG "minzip"
-#include "Zip.h"
-#include "Bits.h"
-#include "Log.h"
-#include "DirUtil.h"
+#include <string>
 
-#undef NDEBUG   // do this after including Log.h
+#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
 #include <assert.h>
-
 #include <selinux/label.h>
 #include <selinux/selinux.h>
 
+#include "Zip.h"
+#include "Bits.h"
+#include "DirUtil.h"
+
 #define SORT_ENTRIES 1
 
 /*
@@ -154,8 +154,9 @@
     found = (const ZipEntry*)mzHashTableLookup(pHash,
                 itemHash, pEntry, hashcmpZipEntry, true);
     if (found != pEntry) {
-        LOGW("WARNING: duplicate entry '%.*s' in Zip\n",
-            found->fileNameLen, found->fileName);
+        LOG(WARNING) << "WARNING: duplicate entry '" << std::string(found->fileName,
+                     found->fileNameLen) << "' in Zip";
+
         /* keep going */
     }
 }
@@ -164,7 +165,7 @@
 {
     // Forbid super long filenames.
     if (fileNameLen >= PATH_MAX) {
-        LOGW("Filename too long (%d chatacters)\n", fileNameLen);
+        LOG(WARNING) << "Filename too long (" << fileNameLen << " chatacters)";
         return 0;
     }
 
@@ -172,7 +173,8 @@
     unsigned int i;
     for (i = 0; i < fileNameLen; ++i) {
         if (fileName[i] < 32 || fileName[i] >= 127) {
-            LOGW("Filename contains invalid character '\%03o'\n", fileName[i]);
+            LOG(WARNING) << android::base::StringPrintf(
+                    "Filename contains invalid character '\%02x'\n", fileName[i]);
             return 0;
         }
     }
@@ -201,10 +203,10 @@
      */
     val = get4LE(pArchive->addr);
     if (val == ENDSIG) {
-        LOGW("Found Zip archive, but it looks empty\n");
+        LOG(WARNING) << "Found Zip archive, but it looks empty";
         goto bail;
     } else if (val != LOCSIG) {
-        LOGW("Not a Zip archive (found 0x%08x)\n", val);
+        LOG(WARNING) << android::base::StringPrintf("Not a Zip archive (found 0x%08x)\n", val);
         goto bail;
     }
 
@@ -220,7 +222,7 @@
         ptr--;
     }
     if (ptr < (const unsigned char*) pArchive->addr) {
-        LOGW("Could not find end-of-central-directory in Zip\n");
+        LOG(WARNING) << "Could not find end-of-central-directory in Zip";
         goto bail;
     }
 
@@ -232,10 +234,10 @@
     numEntries = get2LE(ptr + ENDSUB);
     cdOffset = get4LE(ptr + ENDOFF);
 
-    LOGVV("numEntries=%d cdOffset=%d\n", numEntries, cdOffset);
+    LOG(VERBOSE) << "numEntries=" << numEntries << " cdOffset=" << cdOffset;
     if (numEntries == 0 || cdOffset >= pArchive->length) {
-        LOGW("Invalid entries=%d offset=%d (len=%zd)\n",
-            numEntries, cdOffset, pArchive->length);
+        LOG(WARNING) << "Invalid entries=" << numEntries << " offset=" << cdOffset
+                     << " (len=" << pArchive->length << ")";
         goto bail;
     }
 
@@ -256,11 +258,11 @@
         const char *fileName;
 
         if (ptr + CENHDR > (const unsigned char*)pArchive->addr + pArchive->length) {
-            LOGW("Ran off the end (at %d)\n", i);
+            LOG(WARNING) << "Ran off the end (at " << i << ")";
             goto bail;
         }
         if (get4LE(ptr) != CENSIG) {
-            LOGW("Missed a central dir sig (at %d)\n", i);
+            LOG(WARNING) << "Missed a central dir sig (at " << i << ")";
             goto bail;
         }
 
@@ -270,11 +272,11 @@
         commentLen = get2LE(ptr + CENCOM);
         fileName = (const char*)ptr + CENHDR;
         if (fileName + fileNameLen > (const char*)pArchive->addr + pArchive->length) {
-            LOGW("Filename ran off the end (at %d)\n", i);
+            LOG(WARNING) << "Filename ran off the end (at " << i << ")";
             goto bail;
         }
         if (!validFilename(fileName, fileNameLen)) {
-            LOGW("Invalid filename (at %d)\n", i);
+            LOG(WARNING) << "Invalid filename (at " << i << ")";
             goto bail;
         }
 
@@ -345,7 +347,8 @@
         if ((pEntry->versionMadeBy & 0xff00) != 0 &&
                 (pEntry->versionMadeBy & 0xff00) != CENVEM_UNIX)
         {
-            LOGW("Incompatible \"version made by\": 0x%02x (at %d)\n",
+            LOG(WARNING) << android::base::StringPrintf(
+                    "Incompatible \"version made by\": 0x%02x (at %d)\n",
                     pEntry->versionMadeBy >> 8, i);
             goto bail;
         }
@@ -355,26 +358,27 @@
         // overflow. This is needed because localHdrOffset is untrusted.
         if (!safe_add((uintptr_t *)&localHdr, (uintptr_t)pArchive->addr,
             (uintptr_t)localHdrOffset)) {
-            LOGW("Integer overflow adding in parseZipArchive\n");
+            LOG(WARNING) << "Integer overflow adding in parseZipArchive";
             goto bail;
         }
         if ((uintptr_t)localHdr + LOCHDR >
             (uintptr_t)pArchive->addr + pArchive->length) {
-            LOGW("Bad offset to local header: %d (at %d)\n", localHdrOffset, i);
+            LOG(WARNING) << "Bad offset to local header: " << localHdrOffset
+                         << " (at " << i << ")";
             goto bail;
         }
         if (get4LE(localHdr) != LOCSIG) {
-            LOGW("Missed a local header sig (at %d)\n", i);
+            LOG(WARNING) << "Missed a local header sig (at " << i << ")";
             goto bail;
         }
         pEntry->offset = localHdrOffset + LOCHDR
             + get2LE(localHdr + LOCNAM) + get2LE(localHdr + LOCEXT);
         if (!safe_add(NULL, pEntry->offset, pEntry->compLen)) {
-            LOGW("Integer overflow adding in parseZipArchive\n");
+            LOG(WARNING) << "Integer overflow adding in parseZipArchive";
             goto bail;
         }
         if ((size_t)pEntry->offset + pEntry->compLen > pArchive->length) {
-            LOGW("Data ran off the end (at %d)\n", i);
+            LOG(WARNING) << "Data ran off the end (at " << i << ")";
             goto bail;
         }
 
@@ -432,7 +436,8 @@
 
     if (length < ENDHDR) {
         err = -1;
-        LOGW("Archive %p is too small to be zip (%zd)\n", pArchive, length);
+        LOG(WARNING) << "Archive " << pArchive << " is too small to be zip ("
+                     << length << ")";
         goto bail;
     }
 
@@ -441,7 +446,7 @@
 
     if (!parseZipArchive(pArchive)) {
         err = -1;
-        LOGW("Parsing archive %p failed\n", pArchive);
+        LOG(WARNING) << "Parsing archive " << pArchive << " failed";
         goto bail;
     }
 
@@ -460,7 +465,7 @@
  */
 void mzCloseZipArchive(ZipArchive* pArchive)
 {
-    LOGV("Closing archive %p\n", pArchive);
+    LOG(VERBOSE) << "Closing archive " << pArchive;
 
     free(pArchive->pEntries);
 
@@ -534,10 +539,10 @@
     zerr = inflateInit2(&zstream, -MAX_WBITS);
     if (zerr != Z_OK) {
         if (zerr == Z_VERSION_ERROR) {
-            LOGE("Installed zlib is not compatible with linked version (%s)\n",
-                ZLIB_VERSION);
+            LOG(ERROR) << "Installed zlib is not compatible with linked version ("
+                       << ZLIB_VERSION << ")";
         } else {
-            LOGE("Call to inflateInit2 failed (zerr=%d)\n", zerr);
+            LOG(ERROR) << "Call to inflateInit2 failed (zerr=" << zerr << ")";
         }
         goto bail;
     }
@@ -549,7 +554,7 @@
         /* uncompress the data */
         zerr = inflate(&zstream, Z_NO_FLUSH);
         if (zerr != Z_OK && zerr != Z_STREAM_END) {
-            LOGW("zlib inflate call failed (zerr=%d)\n", zerr);
+            LOG(WARNING) << "zlib inflate call failed (zerr=" << zerr << ")";
             goto z_bail;
         }
 
@@ -558,10 +563,10 @@
             (zerr == Z_STREAM_END && zstream.avail_out != sizeof(procBuf)))
         {
             long procSize = zstream.next_out - procBuf;
-            LOGVV("+++ processing %d bytes\n", (int) procSize);
+            LOG(VERBOSE) << "+++ processing " << procSize << " bytes";
             bool ret = processFunction(procBuf, procSize, cookie);
             if (!ret) {
-                LOGW("Process function elected to fail (in inflate)\n");
+                LOG(WARNING) << "Process function elected to fail (in inflate)";
                 goto z_bail;
             }
 
@@ -582,7 +587,8 @@
 bail:
     if (totalOut != pEntry->uncompLen) {
         if (success) {       // error already shown?
-            LOGW("Size mismatch on inflated file (%lu vs %u)\n", totalOut, pEntry->uncompLen);
+            LOG(WARNING) << "Size mismatch on inflated file (" << totalOut << " vs "
+                         << pEntry->uncompLen << ")";
         }
         return false;
     }
@@ -613,8 +619,8 @@
         ret = processDeflatedEntry(pArchive, pEntry, processFunction, cookie);
         break;
     default:
-        LOGE("Unsupported compression type %d for entry '%s'\n",
-                pEntry->compression, pEntry->fileName);
+        LOG(ERROR) << "Unsupported compression type " << pEntry->compression
+                   << " for entry '" << pEntry->fileName << "'";
         break;
     }
 
@@ -653,7 +659,7 @@
     ret = mzProcessZipEntryContents(pArchive, pEntry, copyProcessFunction,
             (void *)&args);
     if (!ret) {
-        LOGE("Can't extract entry to buffer.\n");
+        LOG(ERROR) << "Can't extract entry to buffer";
         return false;
     }
     return true;
@@ -670,15 +676,15 @@
     while (true) {
         ssize_t n = TEMP_FAILURE_RETRY(write(fd, data+soFar, dataLen-soFar));
         if (n <= 0) {
-            LOGE("Error writing %zd bytes from zip file from %p: %s\n",
-                 dataLen-soFar, data+soFar, strerror(errno));
+            PLOG(ERROR) << "Error writing " << dataLen-soFar << " bytes from zip file from "
+                        << data+soFar;
             return false;
         } else if (n > 0) {
             soFar += n;
             if (soFar == dataLen) return true;
             if (soFar > dataLen) {
-                LOGE("write overrun?  (%zd bytes instead of %d)\n",
-                     soFar, dataLen);
+                LOG(ERROR) << "write overrun?  (" << soFar << " bytes instead of "
+                           << dataLen << ")";
                 return false;
             }
         }
@@ -694,7 +700,7 @@
     bool ret = mzProcessZipEntryContents(pArchive, pEntry, writeProcessFunction,
                                          (void*)(intptr_t)fd);
     if (!ret) {
-        LOGE("Can't extract entry to file.\n");
+        LOG(ERROR) << "Can't extract entry to file.";
         return false;
     }
     return true;
@@ -730,7 +736,7 @@
     bool ret = mzProcessZipEntryContents(pArchive, pEntry,
         bufferProcessFunction, (void*)&bec);
     if (!ret || bec.len != 0) {
-        LOGE("Can't extract entry to memory buffer.\n");
+        LOG(ERROR) << "Can't extract entry to memory buffer.";
         return false;
     }
     return true;
@@ -824,11 +830,11 @@
                         struct selabel_handle *sehnd)
 {
     if (zipDir[0] == '/') {
-        LOGE("mzExtractRecursive(): zipDir must be a relative path.\n");
+        LOG(ERROR) << "mzExtractRecursive(): zipDir must be a relative path.";
         return false;
     }
     if (targetDir[0] != '/') {
-        LOGE("mzExtractRecursive(): targetDir must be an absolute path.\n");
+        LOG(ERROR) << "mzExtractRecursive(): targetDir must be an absolute path.\n";
         return false;
     }
 
@@ -838,7 +844,7 @@
     zipDirLen = strlen(zipDir);
     zpath = (char *)malloc(zipDirLen + 2);
     if (zpath == NULL) {
-        LOGE("Can't allocate %d bytes for zip path\n", zipDirLen + 2);
+        LOG(ERROR) << "Can't allocate " << (zipDirLen + 2) << " bytes for zip path";
         return false;
     }
     /* If zipDir is empty, we'll extract the entire zip file.
@@ -917,8 +923,8 @@
          */
         const char *targetFile = targetEntryPath(&helper, pEntry);
         if (targetFile == NULL) {
-            LOGE("Can't assemble target path for \"%.*s\"\n",
-                    pEntry->fileNameLen, pEntry->fileName);
+            LOG(ERROR) << "Can't assemble target path for \"" << std::string(pEntry->fileName,
+                       pEntry->fileNameLen) << "\"";
             ok = false;
             break;
         }
@@ -942,8 +948,7 @@
             int ret = dirCreateHierarchy(
                     targetFile, UNZIP_DIRMODE, timestamp, true, sehnd);
             if (ret != 0) {
-                LOGE("Can't create containing directory for \"%s\": %s\n",
-                        targetFile, strerror(errno));
+                PLOG(ERROR) << "Can't create containing directory for \"" << targetFile << "\"";
                 ok = false;
                 break;
             }
@@ -957,8 +962,8 @@
              * warn about this for now and preserve older behavior.
              */
             if (mzIsZipEntrySymlink(pEntry)) {
-                LOGE("Symlink entry \"%.*s\" will be output as a regular file.",
-                     pEntry->fileNameLen, pEntry->fileName);
+                LOG(ERROR) << "Symlink entry \"" << std::string(pEntry->fileName,
+                           pEntry->fileNameLen) << "\" will be output as a regular file.";
             }
 
             char *secontext = NULL;
@@ -977,8 +982,7 @@
             }
 
             if (fd < 0) {
-                LOGE("Can't create target file \"%s\": %s\n",
-                        targetFile, strerror(errno));
+                PLOG(ERROR) << "Can't create target file \"" << targetFile << "\"";
                 ok = false;
                 break;
             }
@@ -991,25 +995,25 @@
                 ok = false;
             }
             if (!ok) {
-                LOGE("Error extracting \"%s\"\n", targetFile);
+                LOG(ERROR) << "Error extracting \"" << targetFile << "\"";
                 ok = false;
                 break;
             }
 
             if (timestamp != NULL && utime(targetFile, timestamp)) {
-                LOGE("Error touching \"%s\"\n", targetFile);
+                LOG(ERROR) << "Error touching \"" << targetFile << "\"";
                 ok = false;
                 break;
             }
 
-            LOGV("Extracted file \"%s\"\n", targetFile);
+            LOG(VERBOSE) <<"Extracted file \"" << targetFile << "\"";
             ++extractCount;
         }
 
         if (callback != NULL) callback(targetFile, cookie);
     }
 
-    LOGV("Extracted %d file(s)\n", extractCount);
+    LOG(VERBOSE) << "Extracted " << extractCount << " file(s)";
 
     free(helper.buf);
     free(zpath);
diff --git a/otafault/Android.mk b/otafault/Android.mk
index d0b1174..47c0405 100644
--- a/otafault/Android.mk
+++ b/otafault/Android.mk
@@ -17,10 +17,11 @@
 include $(CLEAR_VARS)
 
 otafault_static_libs := \
-    libbase \
     libminzip \
     libz \
-    libselinux
+    libselinux \
+    libbase \
+    liblog
 
 LOCAL_SRC_FILES := config.cpp ota_io.cpp
 LOCAL_MODULE_TAGS := eng
diff --git a/recovery-persist.cpp b/recovery-persist.cpp
index 25df03f..b0ec141 100644
--- a/recovery-persist.cpp
+++ b/recovery-persist.cpp
@@ -14,8 +14,6 @@
  * limitations under the License.
  */
 
-#define LOG_TAG "recovery-persist"
-
 //
 // Strictly to deal with reboot into system after OTA after /data
 // mounts to pull the last pmsg file data and place it
@@ -40,10 +38,9 @@
 
 #include <string>
 
-#include <android/log.h> /* Android Log Priority Tags */
 #include <android-base/file.h>
-#include <log/log.h>
-#include <log/logger.h> /* Android Log packet format */
+#include <android-base/logging.h>
+
 #include <private/android_logger.h> /* private pmsg functions */
 
 static const char *LAST_LOG_FILE = "/data/misc/recovery/last_log";
@@ -57,14 +54,16 @@
 // close a file, log an error if the error indicator is set
 static void check_and_fclose(FILE *fp, const char *name) {
     fflush(fp);
-    if (ferror(fp)) SLOGE("%s %s", name, strerror(errno));
+    if (ferror(fp)) {
+        PLOG(ERROR) << "Error in " << name;
+    }
     fclose(fp);
 }
 
 static void copy_file(const char* source, const char* destination) {
     FILE* dest_fp = fopen(destination, "w");
     if (dest_fp == nullptr) {
-        SLOGE("%s %s", destination, strerror(errno));
+        PLOG(ERROR) << "Can't open " << destination;
     } else {
         FILE* source_fp = fopen(source, "r");
         if (source_fp != nullptr) {
@@ -157,7 +156,7 @@
     static const char mounts_file[] = "/proc/mounts";
     FILE *fp = fopen(mounts_file, "r");
     if (!fp) {
-        SLOGV("%s %s", mounts_file, strerror(errno));
+        PLOG(ERROR) << "failed to open " << mounts_file;
     } else {
         char *line = NULL;
         size_t len = 0;
diff --git a/recovery.cpp b/recovery.cpp
index 9fbdd8c..aad2464 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -41,6 +41,7 @@
 #include <adb.h>
 #include <android/log.h> /* Android Log Priority Tags */
 #include <android-base/file.h>
+#include <android-base/logging.h>
 #include <android-base/parseint.h>
 #include <android-base/stringprintf.h>
 #include <android-base/strings.h>
@@ -48,7 +49,6 @@
 #include <cutils/android_reboot.h>
 #include <cutils/properties.h>
 #include <healthd/BatteryMonitor.h>
-#include <log/logger.h> /* Android Log packet format */
 #include <private/android_logger.h> /* private pmsg functions */
 #include <selinux/label.h>
 #include <selinux/selinux.h>
@@ -183,7 +183,7 @@
 // open a given path, mounting partitions as necessary
 FILE* fopen_path(const char *path, const char *mode) {
     if (ensure_path_mounted(path) != 0) {
-        LOGE("Can't mount %s\n", path);
+        LOG(ERROR) << "Can't mount " << path;
         return NULL;
     }
 
@@ -198,7 +198,9 @@
 // close a file, log an error if the error indicator is set
 static void check_and_fclose(FILE *fp, const char *name) {
     fflush(fp);
-    if (ferror(fp)) LOGE("Error in %s\n(%s)\n", name, strerror(errno));
+    if (ferror(fp)) {
+        PLOG(ERROR) << "Error in " << name;
+    }
     fclose(fp);
 }
 
@@ -210,7 +212,7 @@
 static void redirect_stdio(const char* filename) {
     int pipefd[2];
     if (pipe(pipefd) == -1) {
-        LOGE("pipe failed: %s\n", strerror(errno));
+        PLOG(ERROR) << "pipe failed";
 
         // Fall back to traditional logging mode without timestamps.
         // If these fail, there's not really anywhere to complain...
@@ -222,7 +224,7 @@
 
     pid_t pid = fork();
     if (pid == -1) {
-        LOGE("fork failed: %s\n", strerror(errno));
+        PLOG(ERROR) << "fork failed";
 
         // Fall back to traditional logging mode without timestamps.
         // If these fail, there's not really anywhere to complain...
@@ -241,14 +243,14 @@
         // Child logger to actually write to the log file.
         FILE* log_fp = fopen(filename, "a");
         if (log_fp == nullptr) {
-            LOGE("fopen \"%s\" failed: %s\n", filename, strerror(errno));
+            PLOG(ERROR) << "fopen \"" << filename << "\" failed";
             close(pipefd[0]);
             _exit(1);
         }
 
         FILE* pipe_fp = fdopen(pipefd[0], "r");
         if (pipe_fp == nullptr) {
-            LOGE("fdopen failed: %s\n", strerror(errno));
+            PLOG(ERROR) << "fdopen failed";
             check_and_fclose(log_fp, filename);
             close(pipefd[0]);
             _exit(1);
@@ -268,7 +270,7 @@
             fflush(log_fp);
         }
 
-        LOGE("getline failed: %s\n", strerror(errno));
+        PLOG(ERROR) << "getline failed";
 
         free(line);
         check_and_fclose(log_fp, filename);
@@ -283,10 +285,10 @@
         setbuf(stderr, nullptr);
 
         if (dup2(pipefd[1], STDOUT_FILENO) == -1) {
-            LOGE("dup2 stdout failed: %s\n", strerror(errno));
+            PLOG(ERROR) << "dup2 stdout failed";
         }
         if (dup2(pipefd[1], STDERR_FILENO) == -1) {
-            LOGE("dup2 stderr failed: %s\n", strerror(errno));
+            PLOG(ERROR) << "dup2 stderr failed";
         }
 
         close(pipefd[1]);
@@ -305,11 +307,13 @@
     stage = strndup(boot.stage, sizeof(boot.stage));
 
     if (boot.command[0] != 0 && boot.command[0] != 255) {
-        LOGI("Boot command: %.*s\n", (int)sizeof(boot.command), boot.command);
+        std::string boot_command = std::string(boot.command, sizeof(boot.command));
+        LOG(INFO) << "Boot command: " << boot_command;
     }
 
     if (boot.status[0] != 0 && boot.status[0] != 255) {
-        LOGI("Boot status: %.*s\n", (int)sizeof(boot.status), boot.status);
+        std::string boot_status = std::string(boot.status, sizeof(boot.status));
+        LOG(INFO) << "Boot status: " << boot_status;
     }
 
     // --- if arguments weren't supplied, look in the bootloader control block
@@ -323,9 +327,10 @@
                 if ((arg = strtok(NULL, "\n")) == NULL) break;
                 (*argv)[*argc] = strdup(arg);
             }
-            LOGI("Got arguments from boot message\n");
+            LOG(INFO) << "Got arguments from boot message";
         } else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) {
-            LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery);
+            std::string boot_recovery = std::string(boot.recovery, 20);
+            LOG(ERROR) << "Bad boot message\n" << "\"" <<boot_recovery << "\"";
         }
     }
 
@@ -350,7 +355,7 @@
             }
 
             check_and_fclose(fp, COMMAND_FILE);
-            LOGI("Got arguments from %s\n", COMMAND_FILE);
+            LOG(INFO) << "Got arguments from " << COMMAND_FILE;
         }
     }
 
@@ -379,14 +384,14 @@
 static void save_kernel_log(const char* destination) {
     int klog_buf_len = klogctl(KLOG_SIZE_BUFFER, 0, 0);
     if (klog_buf_len <= 0) {
-        LOGE("Error getting klog size: %s\n", strerror(errno));
+        PLOG(ERROR) << "Error getting klog size";
         return;
     }
 
     std::string buffer(klog_buf_len, 0);
     int n = klogctl(KLOG_READ_ALL, &buffer[0], klog_buf_len);
     if (n == -1) {
-        LOGE("Error in reading klog: %s\n", strerror(errno));
+        PLOG(ERROR) << "Error in reading klog";
         return;
     }
     buffer.resize(n);
@@ -411,7 +416,7 @@
 static void copy_log_file(const char* source, const char* destination, bool append) {
     FILE* dest_fp = fopen_path(destination, append ? "a" : "w");
     if (dest_fp == nullptr) {
-        LOGE("Can't open %s\n", destination);
+        PLOG(ERROR) << "Can't open " << destination;
     } else {
         FILE* source_fp = fopen(source, "r");
         if (source_fp != nullptr) {
@@ -509,7 +514,7 @@
         size_t len = strlen(locale);
         __pmsg_write(LOCALE_FILE, locale, len);
         if (has_cache) {
-            LOGI("Saving locale \"%s\"\n", locale);
+            LOG(INFO) << "Saving locale \"" << locale << "\"";
             FILE* fp = fopen_path(LOCALE_FILE, "w");
             if (fp != NULL) {
                 fwrite(locale, 1, len, fp);
@@ -530,7 +535,7 @@
     // Remove the command file, so recovery won't repeat indefinitely.
     if (has_cache) {
         if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) {
-            LOGW("Can't unlink %s\n", COMMAND_FILE);
+            LOG(WARNING) << "Can't unlink " << COMMAND_FILE;
         }
         ensure_path_unmounted(CACHE_ROOT);
     }
@@ -670,7 +675,7 @@
             if (ui->WasTextEverVisible()) {
                 continue;
             } else {
-                LOGI("timed out waiting for key input; rebooting.\n");
+                LOG(INFO) << "timed out waiting for key input; rebooting.";
                 ui->EndMenu();
                 return 0; // XXX fixme
             }
@@ -711,7 +716,7 @@
 
     DIR* d = opendir(path);
     if (d == NULL) {
-        LOGE("error opening %s: %s\n", path, strerror(errno));
+        PLOG(ERROR) << "error opening " << path;
         return NULL;
     }
 
@@ -856,13 +861,13 @@
 static bool secure_wipe_partition(const std::string& partition) {
     android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(partition.c_str(), O_WRONLY)));
     if (fd == -1) {
-        LOGE("failed to open \"%s\": %s\n", partition.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to open \"" << partition << "\"";
         return false;
     }
 
     uint64_t range[2] = {0, 0};
     if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) {
-        LOGE("failed to get partition size: %s\n", strerror(errno));
+        PLOG(ERROR) << "failed to get partition size";
         return false;
     }
     printf("Secure-wiping \"%s\" from %" PRIu64 " to %" PRIu64 ".\n",
@@ -901,7 +906,7 @@
 
     std::string partition_list;
     if (!android::base::ReadFileToString(RECOVERY_BRICK, &partition_list)) {
-        LOGE("failed to read \"%s\".\n", RECOVERY_BRICK);
+        LOG(ERROR) << "failed to read \"" << RECOVERY_BRICK << "\"";
         return false;
     }
 
@@ -1064,7 +1069,7 @@
                 sleep(1);
                 continue;
             } else {
-                LOGE("Timed out waiting for the fuse-provided package.\n");
+                LOG(ERROR) << "Timed out waiting for the fuse-provided package.";
                 result = INSTALL_ERROR;
                 kill(child, SIGKILL);
                 break;
@@ -1086,7 +1091,7 @@
     }
 
     if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
-        LOGE("Error exit from the fuse process: %d\n", WEXITSTATUS(status));
+        LOG(ERROR) << "Error exit from the fuse process: " << WEXITSTATUS(status);
     }
 
     ensure_path_unmounted(SDCARD_ROOT);
@@ -1242,6 +1247,18 @@
     }
 }
 
+static constexpr char log_characters[] = "VDIWEF";
+
+void UiLogger(android::base::LogId id, android::base::LogSeverity severity,
+               const char* tag, const char* file, unsigned int line,
+               const char* message) {
+    if (severity >= android::base::ERROR && gCurrentUI != NULL) {
+        gCurrentUI->Print("E:%s\n", message);
+    } else {
+        fprintf(stdout, "%c:%s\n", log_characters[severity], message);
+    }
+}
+
 static bool is_battery_ok() {
     struct healthd_config healthd_config = {
             .batteryStatusPath = android::String8(android::String8::kEmptyString),
@@ -1370,6 +1387,10 @@
 }
 
 int main(int argc, char **argv) {
+    // We don't have logcat yet under recovery; so we'll print error on screen and
+    // log to stdout (which is redirected to recovery.log) as we used to do.
+    android::base::InitLogging(argv, &UiLogger);
+
     // Take last pmsg contents and rewrite it to the current pmsg session.
     static const char filter[] = "recovery/";
     // Do we need to rotate?
@@ -1451,7 +1472,7 @@
             break;
         }
         case '?':
-            LOGE("Invalid command argument\n");
+            LOG(ERROR) << "Invalid command argument";
             continue;
         }
     }
@@ -1543,7 +1564,7 @@
                 fprintf(install_log, "error: %d\n", kLowBattery);
                 fclose(install_log);
             } else {
-                LOGE("failed to open last_install: %s\n", strerror(errno));
+                PLOG(ERROR) << "failed to open last_install";
             }
             status = INSTALL_SKIPPED;
         } else {
diff --git a/roots.cpp b/roots.cpp
index 4936947..fe49f2b 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -26,6 +26,8 @@
 #include <ctype.h>
 #include <fcntl.h>
 
+#include <android-base/logging.h>
+
 #include <fs_mgr.h>
 #include "common.h"
 #include "make_ext4fs.h"
@@ -44,13 +46,13 @@
 
     fstab = fs_mgr_read_fstab("/etc/recovery.fstab");
     if (!fstab) {
-        LOGE("failed to read /etc/recovery.fstab\n");
+        LOG(ERROR) << "failed to read /etc/recovery.fstab";
         return;
     }
 
     ret = fs_mgr_add_entry(fstab, "/tmp", "ramdisk", "ramdisk");
     if (ret < 0 ) {
-        LOGE("failed to add /tmp entry to fstab\n");
+        LOG(ERROR) << "failed to add /tmp entry to fstab";
         fs_mgr_free_fstab(fstab);
         fstab = NULL;
         return;
@@ -74,7 +76,7 @@
 int ensure_path_mounted_at(const char* path, const char* mount_point) {
     Volume* v = volume_for_path(path);
     if (v == NULL) {
-        LOGE("unknown volume for path [%s]\n", path);
+        LOG(ERROR) << "unknown volume for path [" << path << "]";
         return -1;
     }
     if (strcmp(v->fs_type, "ramdisk") == 0) {
@@ -83,7 +85,7 @@
     }
 
     if (!scan_mounted_volumes()) {
-        LOGE("failed to scan mounted volumes\n");
+        LOG(ERROR) << "failed to scan mounted volumes";
         return -1;
     }
 
@@ -104,25 +106,25 @@
                strcmp(v->fs_type, "vfat") == 0) {
         int result = mount(v->blk_device, mount_point, v->fs_type, v->flags, v->fs_options);
         if (result == -1 && fs_mgr_is_formattable(v)) {
-            LOGE("failed to mount %s (%s), formatting ...\n",
-                    mount_point, strerror(errno));
+            LOG(ERROR) << "failed to mount " << mount_point << " (" << strerror(errno)
+                       << ") , formatting.....";
             bool crypt_footer = fs_mgr_is_encryptable(v) && !strcmp(v->key_loc, "footer");
             if (fs_mgr_do_format(v, crypt_footer) == 0) {
                 result = mount(v->blk_device, mount_point, v->fs_type, v->flags, v->fs_options);
             } else {
-                LOGE("failed to format %s (%s)\n", mount_point, strerror(errno));
+                PLOG(ERROR) << "failed to format " << mount_point;
                 return -1;
             }
         }
 
         if (result == -1) {
-            LOGE("failed to mount %s (%s)\n", mount_point, strerror(errno));
+            PLOG(ERROR) << "failed to mount " << mount_point;
             return -1;
         }
         return 0;
     }
 
-    LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, mount_point);
+    LOG(ERROR) << "unknown fs_type \"" << v->fs_type << "\" for " << mount_point;
     return -1;
 }
 
@@ -134,7 +136,7 @@
 int ensure_path_unmounted(const char* path) {
     Volume* v = volume_for_path(path);
     if (v == NULL) {
-        LOGE("unknown volume for path [%s]\n", path);
+        LOG(ERROR) << "unknown volume for path [" << path << "]";
         return -1;
     }
     if (strcmp(v->fs_type, "ramdisk") == 0) {
@@ -143,7 +145,7 @@
     }
 
     if (!scan_mounted_volumes()) {
-        LOGE("failed to scan mounted volumes\n");
+        LOG(ERROR) << "failed to scan mounted volumes";
         return -1;
     }
 
@@ -165,7 +167,7 @@
     }
     waitpid(child, &status, 0);
     if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
-        LOGE("%s failed with status %d\n", path, WEXITSTATUS(status));
+        LOG(ERROR) << path << " failed with status " << WEXITSTATUS(status);
     }
     return WEXITSTATUS(status);
 }
@@ -173,21 +175,21 @@
 int format_volume(const char* volume, const char* directory) {
     Volume* v = volume_for_path(volume);
     if (v == NULL) {
-        LOGE("unknown volume \"%s\"\n", volume);
+        LOG(ERROR) << "unknown volume \"" << volume << "\"";
         return -1;
     }
     if (strcmp(v->fs_type, "ramdisk") == 0) {
         // you can't format the ramdisk.
-        LOGE("can't format_volume \"%s\"", volume);
+        LOG(ERROR) << "can't format_volume \"" << volume << "\"";
         return -1;
     }
     if (strcmp(v->mount_point, volume) != 0) {
-        LOGE("can't give path \"%s\" to format_volume\n", volume);
+        LOG(ERROR) << "can't give path \"" << volume << "\" to format_volume";
         return -1;
     }
 
     if (ensure_path_unmounted(volume) != 0) {
-        LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point);
+        LOG(ERROR) << "format_volume failed to unmount \"" << v->mount_point << "\"";
         return -1;
     }
 
@@ -195,10 +197,10 @@
         // if there's a key_loc that looks like a path, it should be a
         // block device for storing encryption metadata.  wipe it too.
         if (v->key_loc != NULL && v->key_loc[0] == '/') {
-            LOGI("wiping %s\n", v->key_loc);
+            LOG(INFO) << "wiping " << v->key_loc;
             int fd = open(v->key_loc, O_WRONLY | O_CREAT, 0644);
             if (fd < 0) {
-                LOGE("format_volume: failed to open %s\n", v->key_loc);
+                LOG(ERROR) << "format_volume: failed to open " << v->key_loc;
                 return -1;
             }
             wipe_block_device(fd, get_file_size(fd));
@@ -216,16 +218,19 @@
             result = make_ext4fs_directory(v->blk_device, length, volume, sehandle, directory);
         } else {   /* Has to be f2fs because we checked earlier. */
             if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) {
-                LOGE("format_volume: crypt footer + negative length (%zd) not supported on %s\n", length, v->fs_type);
+                LOG(ERROR) << "format_volume: crypt footer + negative length (" << length
+                           << ") not supported on " << v->fs_type;
                 return -1;
             }
             if (length < 0) {
-                LOGE("format_volume: negative length (%zd) not supported on %s\n", length, v->fs_type);
+                LOG(ERROR) << "format_volume: negative length (" << length
+                           << ") not supported on " << v->fs_type;
                 return -1;
             }
             char *num_sectors;
             if (asprintf(&num_sectors, "%zd", length / 512) <= 0) {
-                LOGE("format_volume: failed to create %s command for %s\n", v->fs_type, v->blk_device);
+                LOG(ERROR) << "format_volume: failed to create " << v->fs_type
+                           << " command for " << v->blk_device;
                 return -1;
             }
             const char *f2fs_path = "/sbin/mkfs.f2fs";
@@ -235,13 +240,13 @@
             free(num_sectors);
         }
         if (result != 0) {
-            LOGE("format_volume: make %s failed on %s with %d(%s)\n", v->fs_type, v->blk_device, result, strerror(errno));
+            PLOG(ERROR) << "format_volume: make " << v->fs_type << " failed on " << v->blk_device;
             return -1;
         }
         return 0;
     }
 
-    LOGE("format_volume: fs_type \"%s\" unsupported\n", v->fs_type);
+    LOG(ERROR) << "format_volume: fs_type \"" << v->fs_type << "\" unsupported";
     return -1;
 }
 
@@ -251,7 +256,7 @@
 
 int setup_install_mounts() {
     if (fstab == NULL) {
-        LOGE("can't set up install mounts: no fstab loaded\n");
+        LOG(ERROR) << "can't set up install mounts: no fstab loaded";
         return -1;
     }
     for (int i = 0; i < fstab->num_entries; ++i) {
@@ -260,13 +265,13 @@
         if (strcmp(v->mount_point, "/tmp") == 0 ||
             strcmp(v->mount_point, "/cache") == 0) {
             if (ensure_path_mounted(v->mount_point) != 0) {
-                LOGE("failed to mount %s\n", v->mount_point);
+                LOG(ERROR) << "failed to mount " << v->mount_point;
                 return -1;
             }
 
         } else {
             if (ensure_path_unmounted(v->mount_point) != 0) {
-                LOGE("failed to unmount %s\n", v->mount_point);
+                LOG(ERROR) << "failed to unmount " << v->mount_point;
                 return -1;
             }
         }
diff --git a/screen_ui.cpp b/screen_ui.cpp
index 3697554..79b5466 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -31,6 +31,7 @@
 
 #include <vector>
 
+#include <android-base/logging.h>
 #include <android-base/strings.h>
 #include <android-base/stringprintf.h>
 #include <cutils/properties.h>
@@ -405,14 +406,14 @@
 void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) {
     int result = res_create_display_surface(filename, surface);
     if (result < 0) {
-        LOGE("couldn't load bitmap %s (error %d)\n", filename, result);
+        LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
     }
 }
 
 void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** surface) {
     int result = res_create_localized_alpha_surface(filename, locale, surface);
     if (result < 0) {
-        LOGE("couldn't load bitmap %s (error %d)\n", filename, result);
+        LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
     }
 }
 
diff --git a/tests/Android.mk b/tests/Android.mk
index 971e5d0..633b3c4 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -46,7 +46,6 @@
 LOCAL_STATIC_LIBRARIES := \
     libapplypatch \
     libotafault \
-    libbase \
     libverifier \
     libcrypto_utils \
     libcrypto \
@@ -55,7 +54,9 @@
     libcutils \
     libbz \
     libz \
-    libc
+    libc \
+    libbase \
+    liblog
 
 testdata_out_path := $(TARGET_OUT_DATA_NATIVE_TESTS)/recovery
 testdata_files := $(call find-subdir-files, testdata/*)
diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp
index 5697712..7adf88c 100644
--- a/uncrypt/uncrypt.cpp
+++ b/uncrypt/uncrypt.cpp
@@ -116,9 +116,6 @@
 #include <cutils/sockets.h>
 #include <fs_mgr.h>
 
-#define LOG_TAG "uncrypt"
-#include <log/log.h>
-
 #define WINDOW_SIZE 5
 
 // uncrypt provides three services: SETUP_BCB, CLEAR_BCB and UNCRYPT.
@@ -139,11 +136,11 @@
 
 static int write_at_offset(unsigned char* buffer, size_t size, int wfd, off64_t offset) {
     if (TEMP_FAILURE_RETRY(lseek64(wfd, offset, SEEK_SET)) == -1) {
-        ALOGE("error seeking to offset %" PRId64 ": %s", offset, strerror(errno));
+        PLOG(ERROR) << "error seeking to offset " << offset;
         return -1;
     }
     if (!android::base::WriteFully(wfd, buffer, size)) {
-        ALOGE("error writing offset %" PRId64 ": %s", offset, strerror(errno));
+        PLOG(ERROR) << "error writing offset " << offset;
         return -1;
     }
     return 0;
@@ -167,13 +164,13 @@
     // The fstab path is always "/fstab.${ro.hardware}".
     char fstab_path[PATH_MAX+1] = "/fstab.";
     if (!property_get("ro.hardware", fstab_path+strlen(fstab_path), "")) {
-        ALOGE("failed to get ro.hardware");
+        LOG(ERROR) << "failed to get ro.hardware";
         return NULL;
     }
 
     fstab = fs_mgr_read_fstab(fstab_path);
     if (!fstab) {
-        ALOGE("failed to read %s", fstab_path);
+        LOG(ERROR) << "failed to read " << fstab_path;
         return NULL;
     }
 
@@ -219,7 +216,7 @@
     CHECK(package_name != nullptr);
     std::string uncrypt_path;
     if (!android::base::ReadFileToString(uncrypt_path_file, &uncrypt_path)) {
-        ALOGE("failed to open \"%s\": %s", uncrypt_path_file.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to open \"" << uncrypt_path_file << "\"";
         return false;
     }
 
@@ -232,33 +229,33 @@
                              bool encrypted, int socket) {
     std::string err;
     if (!android::base::RemoveFileIfExists(map_file, &err)) {
-        ALOGE("failed to remove the existing map file %s: %s", map_file, err.c_str());
+        LOG(ERROR) << "failed to remove the existing map file " << map_file << ": " << err;
         return -1;
     }
     std::string tmp_map_file = std::string(map_file) + ".tmp";
     android::base::unique_fd mapfd(open(tmp_map_file.c_str(),
                                         O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR));
     if (mapfd == -1) {
-        ALOGE("failed to open %s: %s\n", tmp_map_file.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to open " << tmp_map_file;
         return -1;
     }
 
     // Make sure we can write to the socket.
     if (!write_status_to_socket(0, socket)) {
-        ALOGE("failed to write to socket %d\n", socket);
+        LOG(ERROR) << "failed to write to socket " << socket;
         return -1;
     }
 
     struct stat sb;
     if (stat(path, &sb) != 0) {
-        ALOGE("failed to stat %s", path);
+        LOG(ERROR) << "failed to stat " << path;
         return -1;
     }
 
-    ALOGI(" block size: %ld bytes", static_cast<long>(sb.st_blksize));
+    LOG(INFO) << " block size: " << sb.st_blksize << " bytes";
 
     int blocks = ((sb.st_size-1) / sb.st_blksize) + 1;
-    ALOGI("  file size: %" PRId64 " bytes, %d blocks", sb.st_size, blocks);
+    LOG(INFO) << "  file size: " << sb.st_size << " bytes, " << blocks << " blocks";
 
     std::vector<int> ranges;
 
@@ -266,7 +263,7 @@
                        blk_dev, static_cast<int64_t>(sb.st_size),
                        static_cast<int64_t>(sb.st_blksize));
     if (!android::base::WriteStringToFd(s, mapfd)) {
-        ALOGE("failed to write %s: %s", tmp_map_file.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to write " << tmp_map_file;
         return -1;
     }
 
@@ -279,7 +276,7 @@
 
     android::base::unique_fd fd(open(path, O_RDONLY));
     if (fd == -1) {
-        ALOGE("failed to open %s for reading: %s", path, strerror(errno));
+        PLOG(ERROR) << "failed to open " << path << " for reading";
         return -1;
     }
 
@@ -287,7 +284,7 @@
     if (encrypted) {
         wfd.reset(open(blk_dev, O_WRONLY));
         if (wfd == -1) {
-            ALOGE("failed to open fd for writing: %s", strerror(errno));
+            PLOG(ERROR) << "failed to open " << blk_dev << " for writing";
             return -1;
         }
     }
@@ -306,7 +303,7 @@
             // write out head buffer
             int block = head_block;
             if (ioctl(fd, FIBMAP, &block) != 0) {
-                ALOGE("failed to find block %d", head_block);
+                LOG(ERROR) << "failed to find block " << head_block;
                 return -1;
             }
             add_block_to_ranges(ranges, block);
@@ -325,7 +322,7 @@
             size_t to_read = static_cast<size_t>(
                     std::min(static_cast<off64_t>(sb.st_blksize), sb.st_size - pos));
             if (!android::base::ReadFully(fd, buffers[tail].data(), to_read)) {
-                ALOGE("failed to read: %s", strerror(errno));
+                PLOG(ERROR) << "failed to read " << path;
                 return -1;
             }
             pos += to_read;
@@ -342,7 +339,7 @@
         // write out head buffer
         int block = head_block;
         if (ioctl(fd, FIBMAP, &block) != 0) {
-            ALOGE("failed to find block %d", head_block);
+            LOG(ERROR) << "failed to find block " << head_block;
             return -1;
         }
         add_block_to_ranges(ranges, block);
@@ -358,39 +355,39 @@
 
     if (!android::base::WriteStringToFd(
             android::base::StringPrintf("%zu\n", ranges.size() / 2), mapfd)) {
-        ALOGE("failed to write %s: %s", tmp_map_file.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to write " << tmp_map_file;
         return -1;
     }
     for (size_t i = 0; i < ranges.size(); i += 2) {
         if (!android::base::WriteStringToFd(
                 android::base::StringPrintf("%d %d\n", ranges[i], ranges[i+1]), mapfd)) {
-            ALOGE("failed to write %s: %s", tmp_map_file.c_str(), strerror(errno));
+            PLOG(ERROR) << "failed to write " << tmp_map_file;
             return -1;
         }
     }
 
     if (fsync(mapfd) == -1) {
-        ALOGE("failed to fsync \"%s\": %s", tmp_map_file.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to fsync \"" << tmp_map_file << "\"";
         return -1;
     }
     if (close(mapfd.release()) == -1) {
-        ALOGE("failed to close %s: %s", tmp_map_file.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to close " << tmp_map_file;
         return -1;
     }
 
     if (encrypted) {
         if (fsync(wfd) == -1) {
-            ALOGE("failed to fsync \"%s\": %s", blk_dev, strerror(errno));
+            PLOG(ERROR) << "failed to fsync \"" << blk_dev << "\"";
             return -1;
         }
         if (close(wfd.release()) == -1) {
-            ALOGE("failed to close %s: %s", blk_dev, strerror(errno));
+            PLOG(ERROR) << "failed to close " << blk_dev;
             return -1;
         }
     }
 
     if (rename(tmp_map_file.c_str(), map_file) == -1) {
-        ALOGE("failed to rename %s to %s: %s", tmp_map_file.c_str(), map_file, strerror(errno));
+        PLOG(ERROR) << "failed to rename " << tmp_map_file << " to " << map_file;
         return -1;
     }
     // Sync dir to make rename() result written to disk.
@@ -398,28 +395,28 @@
     std::string dir_name = dirname(&file_name[0]);
     android::base::unique_fd dfd(open(dir_name.c_str(), O_RDONLY | O_DIRECTORY));
     if (dfd == -1) {
-        ALOGE("failed to open dir %s: %s", dir_name.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to open dir " << dir_name;
         return -1;
     }
     if (fsync(dfd) == -1) {
-        ALOGE("failed to fsync %s: %s", dir_name.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to fsync " << dir_name;
         return -1;
     }
     if (close(dfd.release()) == -1) {
-        ALOGE("failed to close %s: %s", dir_name.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to close " << dir_name;
         return -1;
     }
     return 0;
 }
 
 static int uncrypt(const char* input_path, const char* map_file, const int socket) {
-    ALOGI("update package is \"%s\"", input_path);
+    LOG(INFO) << "update package is \"" << input_path << "\"";
 
     // Turn the name of the file we're supposed to convert into an
     // absolute path, so we can find what filesystem it's on.
     char path[PATH_MAX+1];
     if (realpath(input_path, path) == NULL) {
-        ALOGE("failed to convert \"%s\" to absolute path: %s", input_path, strerror(errno));
+        PLOG(ERROR) << "failed to convert \"" << input_path << "\" to absolute path";
         return 1;
     }
 
@@ -427,15 +424,15 @@
     bool encrypted;
     const char* blk_dev = find_block_device(path, &encryptable, &encrypted);
     if (blk_dev == NULL) {
-        ALOGE("failed to find block device for %s", path);
+        LOG(ERROR) << "failed to find block device for " << path;
         return 1;
     }
 
     // If the filesystem it's on isn't encrypted, we only produce the
     // block map, we don't rewrite the file contents (it would be
     // pointless to do so).
-    ALOGI("encryptable: %s", encryptable ? "yes" : "no");
-    ALOGI("  encrypted: %s", encrypted ? "yes" : "no");
+    LOG(INFO) << "encryptable: " << (encryptable ? "yes" : "no");
+    LOG(INFO) << "  encrypted: " << (encrypted ? "yes" : "no");
 
     // Recovery supports installing packages from 3 paths: /cache,
     // /data, and /sdcard.  (On a particular device, other locations
@@ -445,7 +442,7 @@
     // can read the package without mounting the partition.  On /cache
     // and /sdcard we leave the file alone.
     if (strncmp(path, "/data/", 6) == 0) {
-        ALOGI("writing block map %s", map_file);
+        LOG(INFO) << "writing block map " << map_file;
         if (produce_block_map(path, map_file, blk_dev, encrypted, socket) != 0) {
             return 1;
         }
@@ -476,7 +473,7 @@
 static bool clear_bcb(const int socket) {
     std::string err;
     if (!clear_bootloader_message(&err)) {
-        ALOGE("failed to clear bootloader message: %s", err.c_str());
+        LOG(ERROR) << "failed to clear bootloader message: " << err;
         write_status_to_socket(-1, socket);
         return false;
     }
@@ -488,7 +485,7 @@
     // c5. receive message length
     int length;
     if (!android::base::ReadFully(socket, &length, 4)) {
-        ALOGE("failed to read the length: %s", strerror(errno));
+        PLOG(ERROR) << "failed to read the length";
         return false;
     }
     length = ntohl(length);
@@ -497,15 +494,15 @@
     std::string content;
     content.resize(length);
     if (!android::base::ReadFully(socket, &content[0], length)) {
-        ALOGE("failed to read the length: %s", strerror(errno));
+        PLOG(ERROR) << "failed to read the length";
         return false;
     }
-    ALOGI("  received command: [%s] (%zu)", content.c_str(), content.size());
+    LOG(INFO) << "  received command: [" << content << "] (" << content.size() << ")";
 
     // c8. setup the bcb command
     std::string err;
     if (!write_bootloader_message({content}, &err)) {
-        ALOGE("failed to set bootloader message: %s", err.c_str());
+        LOG(ERROR) << "failed to set bootloader message: " << err;
         write_status_to_socket(-1, socket);
         return false;
     }
@@ -549,19 +546,19 @@
     // will use the socket to communicate with its caller.
     android::base::unique_fd service_socket(android_get_control_socket(UNCRYPT_SOCKET.c_str()));
     if (service_socket == -1) {
-        ALOGE("failed to open socket \"%s\": %s", UNCRYPT_SOCKET.c_str(), strerror(errno));
+        PLOG(ERROR) << "failed to open socket \"" << UNCRYPT_SOCKET << "\"";
         return 1;
     }
     fcntl(service_socket, F_SETFD, FD_CLOEXEC);
 
     if (listen(service_socket, 1) == -1) {
-        ALOGE("failed to listen on socket %d: %s", service_socket.get(), strerror(errno));
+        PLOG(ERROR) << "failed to listen on socket " << service_socket.get();
         return 1;
     }
 
     android::base::unique_fd socket_fd(accept4(service_socket, nullptr, nullptr, SOCK_CLOEXEC));
     if (socket_fd == -1) {
-        ALOGE("failed to accept on socket %d: %s", service_socket.get(), strerror(errno));
+        PLOG(ERROR) << "failed to accept on socket " << service_socket.get();
         return 1;
     }
 
@@ -577,7 +574,7 @@
             success = clear_bcb(socket_fd);
             break;
         default:  // Should never happen.
-            ALOGE("Invalid uncrypt action code: %d", action);
+            LOG(ERROR) << "Invalid uncrypt action code: " << action;
             return 1;
     }
 
@@ -586,9 +583,9 @@
     // destroyed.
     int code;
     if (android::base::ReadFully(socket_fd, &code, 4)) {
-        ALOGI("  received %d, exiting now", code);
+        LOG(INFO) << "  received " << code << ", exiting now";
     } else {
-        ALOGE("failed to read the code: %s", strerror(errno));
+        PLOG(ERROR) << "failed to read the code";
     }
     return success ? 0 : 1;
 }
diff --git a/update_verifier/Android.mk b/update_verifier/Android.mk
index 7f28bce..ed61c7b 100644
--- a/update_verifier/Android.mk
+++ b/update_verifier/Android.mk
@@ -19,6 +19,6 @@
 LOCAL_CLANG := true
 LOCAL_SRC_FILES := update_verifier.cpp
 LOCAL_MODULE := update_verifier
-LOCAL_SHARED_LIBRARIES := libhardware liblog
+LOCAL_SHARED_LIBRARIES := libhardware libbase
 
 include $(BUILD_EXECUTABLE)
diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp
index be70cec..0a040c5 100644
--- a/update_verifier/update_verifier.cpp
+++ b/update_verifier/update_verifier.cpp
@@ -35,19 +35,17 @@
 
 #include <string.h>
 
+#include <android-base/logging.h>
 #include <hardware/boot_control.h>
 
-#define LOG_TAG       "update_verifier"
-#include <log/log.h>
-
 int main(int argc, char** argv) {
   for (int i = 1; i < argc; i++) {
-    SLOGI("Started with arg %d: %s\n", i, argv[i]);
+    LOG(INFO) << "Started with arg " << i << ": " << argv[i];
   }
 
   const hw_module_t* hw_module;
   if (hw_get_module("bootctrl", &hw_module) != 0) {
-    SLOGE("Error getting bootctrl module.\n");
+    LOG(ERROR) << "Error getting bootctrl module.";
     return -1;
   }
 
@@ -57,7 +55,7 @@
 
   unsigned current_slot = module->getCurrentSlot(module);
   int is_successful= module->isSlotMarkedSuccessful(module, current_slot);
-  SLOGI("Booting slot %u: isSlotMarkedSuccessful=%d\n", current_slot, is_successful);
+  LOG(INFO) << "Booting slot " << current_slot << ": isSlotMarkedSuccessful=" << is_successful;
 
   if (is_successful == 0) {
     // The current slot has not booted successfully.
@@ -70,12 +68,12 @@
 
     int ret = module->markBootSuccessful(module);
     if (ret != 0) {
-      SLOGE("Error marking booted successfully: %s\n", strerror(-ret));
+      LOG(ERROR) << "Error marking booted successfully: " << strerror(-ret);
       return -1;
     }
-    SLOGI("Marked slot %u as booted successfully.\n", current_slot);
+    LOG(INFO) << "Marked slot " << current_slot << " as booted successfully.";
   }
 
-  SLOGI("Leaving update_verifier.\n");
+  LOG(INFO) << "Leaving update_verifier.";
   return 0;
 }
diff --git a/updater/Android.mk b/updater/Android.mk
index b4d427c..e4d73a4 100644
--- a/updater/Android.mk
+++ b/updater/Android.mk
@@ -37,7 +37,6 @@
     libcrypto_utils \
     libcrypto \
     libapplypatch \
-    libbase \
     libotafault \
     libedify \
     libminzip \
@@ -46,7 +45,9 @@
     libbz \
     libcutils \
     liblog \
-    libselinux
+    libselinux \
+    libbase \
+    liblog
 
 tune2fs_static_libraries := \
     libext2_com_err \
diff --git a/verifier.cpp b/verifier.cpp
index 996a1fd..401bd7e 100644
--- a/verifier.cpp
+++ b/verifier.cpp
@@ -22,6 +22,7 @@
 #include <algorithm>
 #include <memory>
 
+#include <android-base/logging.h>
 #include <openssl/bn.h>
 #include <openssl/ecdsa.h>
 #include <openssl/obj_mac.h>
@@ -131,24 +132,24 @@
 #define FOOTER_SIZE 6
 
     if (length < FOOTER_SIZE) {
-        LOGE("not big enough to contain footer\n");
+        LOG(ERROR) << "not big enough to contain footer";
         return VERIFY_FAILURE;
     }
 
     unsigned char* footer = addr + length - FOOTER_SIZE;
 
     if (footer[2] != 0xff || footer[3] != 0xff) {
-        LOGE("footer is wrong\n");
+        LOG(ERROR) << "footer is wrong";
         return VERIFY_FAILURE;
     }
 
     size_t comment_size = footer[4] + (footer[5] << 8);
     size_t signature_start = footer[0] + (footer[1] << 8);
-    LOGI("comment is %zu bytes; signature %zu bytes from end\n",
-         comment_size, signature_start);
+    LOG(INFO) << "comment is " << comment_size << " bytes; signature is " << signature_start
+              << " bytes from end";
 
     if (signature_start <= FOOTER_SIZE) {
-        LOGE("Signature start is in the footer");
+        LOG(ERROR) << "Signature start is in the footer";
         return VERIFY_FAILURE;
     }
 
@@ -159,7 +160,7 @@
     size_t eocd_size = comment_size + EOCD_HEADER_SIZE;
 
     if (length < eocd_size) {
-        LOGE("not big enough to contain EOCD\n");
+        LOG(ERROR) << "not big enough to contain EOCD";
         return VERIFY_FAILURE;
     }
 
@@ -175,7 +176,7 @@
     // magic number $50 $4b $05 $06.
     if (eocd[0] != 0x50 || eocd[1] != 0x4b ||
         eocd[2] != 0x05 || eocd[3] != 0x06) {
-        LOGE("signature length doesn't match EOCD marker\n");
+        LOG(ERROR) << "signature length doesn't match EOCD marker";
         return VERIFY_FAILURE;
     }
 
@@ -186,7 +187,7 @@
             // the real one, minzip will find the later (wrong) one,
             // which could be exploitable.  Fail verification if
             // this sequence occurs anywhere after the real one.
-            LOGE("EOCD marker occurs after start of EOCD\n");
+            LOG(ERROR) << "EOCD marker occurs after start of EOCD";
             return VERIFY_FAILURE;
         }
     }
@@ -235,12 +236,11 @@
     uint8_t* signature = eocd + eocd_size - signature_start;
     size_t signature_size = signature_start - FOOTER_SIZE;
 
-    LOGI("signature (offset: 0x%zx, length: %zu): %s\n",
-            length - signature_start, signature_size,
-            print_hex(signature, signature_size).c_str());
+    LOG(INFO) << "signature (offset: " << std::hex << (length - signature_start) << ", length: "
+              << signature_size << "): " << print_hex(signature, signature_size);
 
     if (!read_pkcs7(signature, signature_size, &sig_der, &sig_der_length)) {
-        LOGE("Could not find signature DER block\n");
+        LOG(ERROR) << "Could not find signature DER block";
         return VERIFY_FAILURE;
     }
 
@@ -271,38 +271,38 @@
         if (key.key_type == Certificate::KEY_TYPE_RSA) {
             if (!RSA_verify(hash_nid, hash, key.hash_len, sig_der,
                             sig_der_length, key.rsa.get())) {
-                LOGI("failed to verify against RSA key %zu\n", i);
+                LOG(INFO) << "failed to verify against RSA key " << i;
                 continue;
             }
 
-            LOGI("whole-file signature verified against RSA key %zu\n", i);
+            LOG(INFO) << "whole-file signature verified against RSA key " << i;
             free(sig_der);
             return VERIFY_SUCCESS;
         } else if (key.key_type == Certificate::KEY_TYPE_EC
                 && key.hash_len == SHA256_DIGEST_LENGTH) {
             if (!ECDSA_verify(0, hash, key.hash_len, sig_der,
                               sig_der_length, key.ec.get())) {
-                LOGI("failed to verify against EC key %zu\n", i);
+                LOG(INFO) << "failed to verify against EC key " << i;
                 continue;
             }
 
-            LOGI("whole-file signature verified against EC key %zu\n", i);
+            LOG(INFO) << "whole-file signature verified against EC key " << i;
             free(sig_der);
             return VERIFY_SUCCESS;
         } else {
-            LOGI("Unknown key type %d\n", key.key_type);
+            LOG(INFO) << "Unknown key type " << key.key_type;
         }
         i++;
     }
 
     if (need_sha1) {
-        LOGI("SHA-1 digest: %s\n", print_hex(sha1, SHA_DIGEST_LENGTH).c_str());
+        LOG(INFO) << "SHA-1 digest: " << print_hex(sha1, SHA_DIGEST_LENGTH);
     }
     if (need_sha256) {
-        LOGI("SHA-256 digest: %s\n", print_hex(sha256, SHA256_DIGEST_LENGTH).c_str());
+        LOG(INFO) << "SHA-256 digest: " << print_hex(sha256, SHA256_DIGEST_LENGTH);
     }
     free(sig_der);
-    LOGE("failed to verify whole-file signature\n");
+    LOG(ERROR) << "failed to verify whole-file signature";
     return VERIFY_FAILURE;
 }
 
@@ -323,7 +323,7 @@
     }
 
     if (key_len_words > 8192 / 32) {
-        LOGE("key length (%d) too large\n", key_len_words);
+        LOG(ERROR) << "key length (" << key_len_words << ") too large";
         return nullptr;
     }
 
@@ -479,7 +479,7 @@
 bool load_keys(const char* filename, std::vector<Certificate>& certs) {
     std::unique_ptr<FILE, decltype(&fclose)> f(fopen(filename, "r"), fclose);
     if (!f) {
-        LOGE("opening %s: %s\n", filename, strerror(errno));
+        PLOG(ERROR) << "error opening " << filename;
         return false;
     }
 
@@ -529,14 +529,14 @@
               return false;
             }
 
-            LOGI("read key e=%d hash=%d\n", exponent, cert.hash_len);
+            LOG(INFO) << "read key e=" << exponent << " hash=" << cert.hash_len;
         } else if (cert.key_type == Certificate::KEY_TYPE_EC) {
             cert.ec = parse_ec_key(f.get());
             if (!cert.ec) {
               return false;
             }
         } else {
-            LOGE("Unknown key type %d\n", cert.key_type);
+            LOG(ERROR) << "Unknown key type " << cert.key_type;
             return false;
         }
 
@@ -548,7 +548,7 @@
         } else if (ch == EOF) {
             break;
         } else {
-            LOGE("unexpected character between keys\n");
+            LOG(ERROR) << "unexpected character between keys";
             return false;
         }
     }
diff --git a/wear_touch.cpp b/wear_touch.cpp
index 51a1d31..cf33daa 100644
--- a/wear_touch.cpp
+++ b/wear_touch.cpp
@@ -14,9 +14,6 @@
  * limitations under the License.
  */
 
-#include "common.h"
-#include "wear_touch.h"
-
 #include <dirent.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -25,8 +22,11 @@
 #include <errno.h>
 #include <string.h>
 
+#include <android-base/logging.h>
 #include <linux/input.h>
 
+#include "wear_touch.h"
+
 #define DEVICE_PATH "/dev/input"
 
 WearSwipeDetector::WearSwipeDetector(int low, int high, OnSwipeCallback callback, void* cookie):
@@ -49,11 +49,11 @@
     } else if (abs(dx) < mLowThreshold && abs(dy) > mHighThreshold) {
         direction = dy < 0 ? UP : DOWN;
     } else {
-        LOGD("Ignore %d %d\n", dx, dy);
+        LOG(DEBUG) << "Ignore " << dx << " " << dy;
         return;
     }
 
-    LOGD("Swipe direction=%d\n", direction);
+    LOG(DEBUG) << "Swipe direction=" << direction;
     mCallback(mCookie, direction);
 }
 
@@ -105,7 +105,7 @@
 void WearSwipeDetector::run() {
     int fd = findDevice(DEVICE_PATH);
     if (fd < 0) {
-        LOGE("no input devices found\n");
+        LOG(ERROR) << "no input devices found";
         return;
     }
 
@@ -127,14 +127,14 @@
 int WearSwipeDetector::openDevice(const char *device) {
     int fd = open(device, O_RDONLY);
     if (fd < 0) {
-        LOGE("could not open %s, %s\n", device, strerror(errno));
+        PLOG(ERROR) << "could not open " << device;
         return false;
     }
 
     char name[80];
     name[sizeof(name) - 1] = '\0';
     if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
-        LOGE("could not get device name for %s, %s\n", device, strerror(errno));
+        PLOG(ERROR) << "could not get device name for " << device;
         name[0] = '\0';
     }
 
@@ -143,7 +143,7 @@
     int ret = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(bits)), bits);
     if (ret > 0) {
         if (test_bit(ABS_MT_POSITION_X, bits) && test_bit(ABS_MT_POSITION_Y, bits)) {
-            LOGD("Found %s %s\n", device, name);
+            LOG(DEBUG) << "Found " << device << " " << name;
             return fd;
         }
     }
@@ -155,7 +155,7 @@
 int WearSwipeDetector::findDevice(const char* path) {
     DIR* dir = opendir(path);
     if (dir == NULL) {
-        LOGE("Could not open directory %s", path);
+        PLOG(ERROR) << "Could not open directory " << path;
         return false;
     }