Merge e5b4d07b6728073c5520a25d29abf8df004a5dc2 on remote branch

Change-Id: I64a8b5c06c899cffd92057819ae576ca4ebe5d8b
diff --git a/Android.bp b/Android.bp
index 47afd21..9a59df3 100644
--- a/Android.bp
+++ b/Android.bp
@@ -33,22 +33,6 @@
     host_supported: true,
 }
 
-// TODO(b/67435044) Update the include paths and remove this
-cc_library_headers {
-    name: "cuttlefish_glog",
-    vendor: true,
-    export_include_dirs: ["common/libs"],
-    host_supported: true,
-}
-
-// TODO(b/67435044) Update the include paths and remove this
-cc_library_headers {
-    name: "cuttlefish_glog_product",
-    product_specific: true,
-    export_include_dirs: ["common/libs"],
-    host_supported: true,
-}
-
 cc_defaults {
     name: "cuttlefish_base",
     gnu_extensions: false,
diff --git a/common/frontend/socket_vsock_proxy/Android.bp b/common/frontend/socket_vsock_proxy/Android.bp
index 310244a..c9684a5 100644
--- a/common/frontend/socket_vsock_proxy/Android.bp
+++ b/common/frontend/socket_vsock_proxy/Android.bp
@@ -27,9 +27,6 @@
     static_libs: [
         "libgflags",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     target: {
         host: {
             static_libs: [
diff --git a/common/frontend/socket_vsock_proxy/main.cpp b/common/frontend/socket_vsock_proxy/main.cpp
index c11852f..78ca859 100644
--- a/common/frontend/socket_vsock_proxy/main.cpp
+++ b/common/frontend/socket_vsock_proxy/main.cpp
@@ -16,11 +16,15 @@
 
 #include <set>
 #include <thread>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <gflags/gflags.h>
 
 #include "common/libs/fs/shared_fd.h"
 
+#ifdef CUTTLEFISH_HOST
+#include "host/libs/config/logging.h"
+#endif // CUTTLEFISH_HOST
+
 constexpr std::size_t kMaxPacketSize = 8192;
 
 DEFINE_string(server, "",
@@ -216,7 +220,12 @@
 }  // namespace
 
 int main(int argc, char* argv[]) {
-  gflags::ParseCommandLineFlags(&argc, &argv, true);
+#ifdef CUTTLEFISH_HOST
+  cvd::DefaultSubprocessLogging(argv);
+#else
+  ::android::base::InitLogging(argv, android::base::LogdLogger());
+#endif
+  google::ParseCommandLineFlags(&argc, &argv, true);
 
   CHECK(FLAGS_tcp_port != 0) << "Must specify -tcp_port flag";
   CHECK(FLAGS_vsock_port != 0) << "Must specify -vsock_port flag";
diff --git a/common/libs/device_config/Android.bp b/common/libs/device_config/Android.bp
index 4900d35..7ce7395 100644
--- a/common/libs/device_config/Android.bp
+++ b/common/libs/device_config/Android.bp
@@ -18,9 +18,6 @@
     srcs: [
         "device_config.cpp",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libbase",
         "liblog",
diff --git a/common/libs/device_config/device_config.cpp b/common/libs/device_config/device_config.cpp
index 69c489f..c13f869 100644
--- a/common/libs/device_config/device_config.cpp
+++ b/common/libs/device_config/device_config.cpp
@@ -19,7 +19,7 @@
 #include <sstream>
 #include <type_traits>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 namespace cvd {
 
diff --git a/common/libs/device_config/guest_device_config.cpp b/common/libs/device_config/guest_device_config.cpp
index fc2c587..0be87be 100644
--- a/common/libs/device_config/guest_device_config.cpp
+++ b/common/libs/device_config/guest_device_config.cpp
@@ -20,7 +20,7 @@
 #include <thread>
 
 #include <cutils/properties.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 namespace cvd {
 
diff --git a/common/libs/device_config/host_device_config.cpp b/common/libs/device_config/host_device_config.cpp
index 5359a06..65f82f6 100644
--- a/common/libs/device_config/host_device_config.cpp
+++ b/common/libs/device_config/host_device_config.cpp
@@ -15,7 +15,7 @@
  */
 
 #include <arpa/inet.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <ifaddrs.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/common/libs/fs/Android.bp b/common/libs/fs/Android.bp
index 0e49e5a..88189dc 100644
--- a/common/libs/fs/Android.bp
+++ b/common/libs/fs/Android.bp
@@ -18,7 +18,6 @@
     srcs: [
         "shared_buf.cc",
         "shared_fd.cpp",
-        "tee.cpp",
     ],
     shared: {
         shared_libs: [
@@ -47,7 +46,6 @@
     srcs: [
         "shared_buf.cc",
         "shared_fd.cpp",
-        "tee.cpp",
     ],
     shared_libs: [
         "libbase",
@@ -62,7 +60,6 @@
     srcs: [
         "shared_fd_test.cpp",
     ],
-    header_libs: ["cuttlefish_glog"],
     shared_libs: [
         "libcuttlefish_fs",
         "libbase",
diff --git a/common/libs/fs/shared_fd.cpp b/common/libs/fs/shared_fd.cpp
index f02a0e9..0386dd9 100644
--- a/common/libs/fs/shared_fd.cpp
+++ b/common/libs/fs/shared_fd.cpp
@@ -27,7 +27,7 @@
 #include <algorithm>
 #include <vector>
 
-#include "common/libs/glog/logging.h"
+#include "android-base/logging.h"
 #include "common/libs/fs/shared_select.h"
 
 // #define ENABLE_GCE_SHARED_FD_LOGGING 1
diff --git a/common/libs/fs/shared_fd.h b/common/libs/fs/shared_fd.h
index bf54dfa..7bcac6a 100644
--- a/common/libs/fs/shared_fd.h
+++ b/common/libs/fs/shared_fd.h
@@ -259,6 +259,25 @@
   // in probably isn't modified, but the API spec doesn't have const.
   bool IsSet(fd_set* in) const;
 
+  /**
+   * Adds a hard link to a file descriptor, based on the current working
+   * directory of the process or to some absolute path.
+   *
+   * https://www.man7.org/linux/man-pages/man2/linkat.2.html
+   *
+   * Using this on a file opened with O_TMPFILE can link it into the filesystem.
+   */
+  // Used with O_TMPFILE files to attach them to the filesystem.
+  int LinkAtCwd(const std::string& path) {
+    std::string name = "/proc/self/fd/";
+    name += std::to_string(fd_);
+    errno = 0;
+    int rval = linkat(
+        -1, name.c_str(), AT_FDCWD, path.c_str(), AT_SYMLINK_FOLLOW);
+    errno_ = errno;
+    return rval;
+  }
+
   int Listen(int backlog) {
     errno = 0;
     int rval = listen(fd_, backlog);
diff --git a/common/libs/fs/tee.cpp b/common/libs/fs/tee.cpp
deleted file mode 100644
index 87ad432..0000000
--- a/common/libs/fs/tee.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-//
-// Copyright (C) 2019 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <algorithm>
-#include <iostream>
-
-#include "common/libs/glog/logging.h"
-#include "common/libs/fs/shared_buf.h"
-#include "common/libs/fs/tee.h"
-
-static const std::size_t READ_SIZE = 512;
-
-namespace cvd {
-
-TeeSubscriber* Tee::AddSubscriber(TeeSubscriber subscriber) {
-  if (reader_.joinable()) {
-    return nullptr;
-  }
-  return &targets_.emplace_back(std::move(subscriber)).handler;
-}
-
-void Tee::Start(SharedFD source) {
-  reader_ = std::thread([this, source]() {
-    while (true) {
-      // TODO(schfufelen): Use multiple buffers at once for readv
-      // TODO(schuffelen): Reuse buffers
-      TeeBufferPtr buffer = std::make_shared<std::vector<char>>(READ_SIZE);
-      ssize_t read = source->Read(buffer->data(), buffer->size());
-      if (read <= 0) {
-        for (auto& target : targets_) {
-          target.content_queue.Push(nullptr);
-        }
-        break;
-      }
-      buffer->resize(read);
-      for (auto& target : targets_) {
-        target.content_queue.Push(buffer);
-      }
-    }
-  });
-  for (auto& target : targets_) {
-    target.runner = std::thread([&target]() {
-      while (true) {
-        auto queue_chunk = target.content_queue.PopAll();
-        // TODO(schuffelen): Pass multiple buffers to support writev
-        for (auto& buffer : queue_chunk) {
-          if (!buffer) {
-            return;
-          }
-          target.handler(buffer);
-        }
-      }
-    });
-  }
-}
-
-Tee::~Tee() {
-  Join();
-}
-
-void Tee::Join() {
-  if (reader_.joinable()) {
-    reader_.join();
-  }
-  auto it = targets_.begin();
-  while (it != targets_.end()) {
-    if (it->runner.joinable()) {
-      it->runner.join();
-    }
-    it = targets_.erase(it);
-  }
-}
-
-TeeSubscriber SharedFDWriter(SharedFD fd) {
-  return [fd](const TeeBufferPtr buffer) { WriteAll(fd, *buffer); };
-}
-
-// An alternative to this would have been to modify the logger, but that would
-// not capture logs from subprocesses.
-TeeStderrToFile::TeeStderrToFile() {
-  original_stderr_ = SharedFD::Dup(2);
-
-  SharedFD stderr_read, stderr_write;
-  SharedFD::Pipe(&stderr_read, &stderr_write);
-  stderr_write->UNMANAGED_Dup2(2);
-  stderr_write->Close();
-
-  tee_.AddSubscriber(SharedFDWriter(original_stderr_));
-  tee_.AddSubscriber(
-      [this](cvd::TeeBufferPtr data) {
-        std::unique_lock lock(mutex_);
-        while (!log_file_->IsOpen()) {
-          notifier_.wait(lock);
-        }
-        cvd::WriteAll(log_file_, *data);
-      });
-  tee_.Start(std::move(stderr_read));
-}
-
-TeeStderrToFile::~TeeStderrToFile() {
-  original_stderr_->UNMANAGED_Dup2(2);
-}
-
-void TeeStderrToFile::SetFile(SharedFD file) {
-  std::lock_guard lock(mutex_);
-  log_file_ = file;
-  notifier_.notify_all();
-}
-
-} // namespace
diff --git a/common/libs/fs/tee.h b/common/libs/fs/tee.h
deleted file mode 100644
index 23bc3d1..0000000
--- a/common/libs/fs/tee.h
+++ /dev/null
@@ -1,70 +0,0 @@
-//
-// Copyright (C) 2019 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma once
-
-#include <condition_variable>
-#include <functional>
-#include <list>
-#include <memory>
-#include <mutex>
-#include <thread>
-#include <string>
-#include <vector>
-
-#include "common/libs/fs/shared_fd.h"
-#include "common/libs/thread_safe_queue/thread_safe_queue.h"
-
-namespace cvd {
-
-using TeeBufferPtr = std::shared_ptr<std::vector<char>>;
-using TeeSubscriber = std::function<void(const TeeBufferPtr)>;
-
-struct TeeTarget {
-  std::thread runner;
-  ThreadSafeQueue<TeeBufferPtr> content_queue;
-  TeeSubscriber handler;
-
-  TeeTarget(TeeSubscriber handler) : handler(handler) {}
-};
-
-class Tee {
-  std::thread reader_;
-  std::list<TeeTarget> targets_;
-public:
-  ~Tee();
-
-  TeeSubscriber* AddSubscriber(TeeSubscriber);
-
-  void Start(SharedFD source);
-  void Join();
-};
-
-TeeSubscriber SharedFDWriter(SharedFD fd);
-
-class TeeStderrToFile {
-  cvd::SharedFD log_file_;
-  cvd::SharedFD original_stderr_;
-  std::condition_variable notifier_;
-  std::mutex mutex_;
-  Tee tee_; // This should be destroyed first, so placed last.
-public:
-  TeeStderrToFile();
-  ~TeeStderrToFile();
-
-  void SetFile(SharedFD file);
-};
-
-} // namespace cvd
diff --git a/common/libs/glog/logging.h b/common/libs/glog/logging.h
deleted file mode 100644
index 8cd4a8a..0000000
--- a/common/libs/glog/logging.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#pragma once
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifdef ANDROID
-#include <android-base/logging.h>
-
-#if defined(CUTTLEFISH_HOST)
-using ::android::base::VERBOSE;
-using ::android::base::INFO;
-using ::android::base::WARNING;
-using ::android::base::FATAL;
-
-#define LOG_IF(LEVEL, CONDITION) if (CONDITION) LOG(LEVEL)
-
-#endif  // CUTTLEFISH_HOST
-#else  // DEBIAN_HOST (by elimination)
-#include <glog/logging.h>
-#endif
diff --git a/common/libs/net/Android.bp b/common/libs/net/Android.bp
index ba7bbd3..8028c75 100644
--- a/common/libs/net/Android.bp
+++ b/common/libs/net/Android.bp
@@ -31,7 +31,6 @@
     srcs: [
         "netlink_request_test.cpp",
     ],
-    header_libs: ["cuttlefish_glog"],
     shared_libs: [
         "libcuttlefish_fs",
         "cuttlefish_net",
diff --git a/common/libs/net/netlink_client.cpp b/common/libs/net/netlink_client.cpp
index 96eb4a9..624b1a7 100644
--- a/common/libs/net/netlink_client.cpp
+++ b/common/libs/net/netlink_client.cpp
@@ -22,7 +22,7 @@
 #include <sys/socket.h>
 
 #include "common/libs/fs/shared_fd.h"
-#include "common/libs/glog/logging.h"
+#include "android-base/logging.h"
 
 namespace cvd {
 namespace {
diff --git a/common/libs/net/netlink_request.cpp b/common/libs/net/netlink_request.cpp
index 68adcf0..bc7c1cf 100644
--- a/common/libs/net/netlink_request.cpp
+++ b/common/libs/net/netlink_request.cpp
@@ -24,7 +24,7 @@
 #include <string>
 #include <vector>
 
-#include "common/libs/glog/logging.h"
+#include "android-base/logging.h"
 
 namespace cvd {
 namespace {
diff --git a/common/libs/net/netlink_request_test.cpp b/common/libs/net/netlink_request_test.cpp
index 03a7dad..2410b02 100644
--- a/common/libs/net/netlink_request_test.cpp
+++ b/common/libs/net/netlink_request_test.cpp
@@ -19,7 +19,7 @@
 
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <iostream>
 #include <memory>
diff --git a/common/libs/net/network_interface_manager.cpp b/common/libs/net/network_interface_manager.cpp
index 0d1dc56..b61ba33 100644
--- a/common/libs/net/network_interface_manager.cpp
+++ b/common/libs/net/network_interface_manager.cpp
@@ -24,7 +24,7 @@
 
 #include <memory>
 
-#include "common/libs/glog/logging.h"
+#include "android-base/logging.h"
 #include "common/libs/net/network_interface.h"
 
 namespace cvd {
diff --git a/common/libs/tcp_socket/Android.bp b/common/libs/tcp_socket/Android.bp
index c5f9550..5b01bab 100644
--- a/common/libs/tcp_socket/Android.bp
+++ b/common/libs/tcp_socket/Android.bp
@@ -23,8 +23,5 @@
         "libcuttlefish_fs",
         "liblog",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     defaults: ["cuttlefish_host_and_guest"],
 }
diff --git a/common/libs/tcp_socket/tcp_socket.cpp b/common/libs/tcp_socket/tcp_socket.cpp
index 64da7d7..2775c29 100644
--- a/common/libs/tcp_socket/tcp_socket.cpp
+++ b/common/libs/tcp_socket/tcp_socket.cpp
@@ -22,7 +22,7 @@
 
 #include <cerrno>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 using cvd::ClientSocket;
 using cvd::ServerSocket;
diff --git a/common/libs/utils/Android.bp b/common/libs/utils/Android.bp
index 268862f..3c7e519 100644
--- a/common/libs/utils/Android.bp
+++ b/common/libs/utils/Android.bp
@@ -23,9 +23,7 @@
         "files.cpp",
         "users.cpp",
         "network.cpp",
-    ],
-    header_libs: [
-        "cuttlefish_glog",
+        "tee_logging.cpp",
     ],
     shared: {
         shared_libs: [
diff --git a/common/libs/utils/archive.cpp b/common/libs/utils/archive.cpp
index 36e6576..10ca95a 100644
--- a/common/libs/utils/archive.cpp
+++ b/common/libs/utils/archive.cpp
@@ -20,7 +20,7 @@
 #include <vector>
 
 #include <android-base/strings.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/utils/subprocess.h"
 
diff --git a/common/libs/utils/files.cpp b/common/libs/utils/files.cpp
index 3d0ba06..833806f 100644
--- a/common/libs/utils/files.cpp
+++ b/common/libs/utils/files.cpp
@@ -16,12 +16,13 @@
 
 #include "common/libs/utils/files.h"
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <array>
 #include <climits>
 #include <cstdio>
 #include <cstdlib>
+#include <fstream>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -83,11 +84,33 @@
   return std::chrono::system_clock::time_point(seconds);
 }
 
+bool RenameFile(const std::string& old_name, const std::string& new_name) {
+  LOG(INFO) << "Renaming " << old_name << " to " << new_name;
+  if(rename(old_name.c_str(), new_name.c_str())) {
+    LOG(ERROR) << "File rename failed due to " << strerror(errno);
+    return false;
+  }
+
+  return true;
+}
+
 bool RemoveFile(const std::string& file) {
   LOG(INFO) << "Removing " << file;
   return remove(file.c_str()) == 0;
 }
 
+
+std::string ReadFile(const std::string& file) {
+  std::string contents;
+  std::ifstream in(file, std::ios::in | std::ios::binary);
+  in.seekg(0, std::ios::end);
+  contents.resize(in.tellg());
+  in.seekg(0, std::ios::beg);
+  in.read(&contents[0], contents.size());
+  in.close();
+  return(contents);
+}
+
 std::string CurrentDirectory() {
   char* path = getcwd(nullptr, 0);
   std::string ret(path);
diff --git a/common/libs/utils/files.h b/common/libs/utils/files.h
index d42edc5..b2b4d91 100644
--- a/common/libs/utils/files.h
+++ b/common/libs/utils/files.h
@@ -26,6 +26,8 @@
 bool DirectoryExists(const std::string& path);
 off_t FileSize(const std::string& path);
 bool RemoveFile(const std::string& file);
+bool RenameFile(const std::string& old_name, const std::string& new_name);
+std::string ReadFile(const std::string& file);
 std::chrono::system_clock::time_point FileModificationTime(const std::string& path);
 
 // The returned value may contain .. or . if these are present in the path
diff --git a/common/libs/utils/network.cpp b/common/libs/utils/network.cpp
index 5b67c8e..f120949 100644
--- a/common/libs/utils/network.cpp
+++ b/common/libs/utils/network.cpp
@@ -21,7 +21,7 @@
 #include <string.h>
 
 #include <android-base/strings.h>
-#include "common/libs/glog/logging.h"
+#include "android-base/logging.h"
 
 #include "common/libs/utils/environment.h"
 #include "common/libs/utils/subprocess.h"
diff --git a/common/libs/utils/subprocess.cpp b/common/libs/utils/subprocess.cpp
index 23cce91..1b23840 100644
--- a/common/libs/utils/subprocess.cpp
+++ b/common/libs/utils/subprocess.cpp
@@ -28,7 +28,7 @@
 #include <set>
 #include <thread>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_buf.h"
 
diff --git a/common/libs/utils/tee_logging.cpp b/common/libs/utils/tee_logging.cpp
new file mode 100644
index 0000000..650a813
--- /dev/null
+++ b/common/libs/utils/tee_logging.cpp
@@ -0,0 +1,200 @@
+//
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "tee_logging.h"
+
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include <android-base/stringprintf.h>
+#include <android-base/strings.h>
+#include <android-base/threads.h>
+
+#include "common/libs/fs/shared_buf.h"
+
+using android::base::GetThreadId;
+using android::base::FATAL;
+using android::base::LogSeverity;
+using android::base::StringPrintf;
+
+namespace cvd {
+
+static LogSeverity GuessSeverity(
+    const std::string& env_var, LogSeverity default_value) {
+  using android::base::VERBOSE;
+  using android::base::DEBUG;
+  using android::base::INFO;
+  using android::base::WARNING;
+  using android::base::ERROR;
+  using android::base::FATAL_WITHOUT_ABORT;
+  using android::base::FATAL;
+  char* env_cstr = getenv(env_var.c_str());
+  std::string env_value(env_cstr == nullptr ? "" : env_cstr);
+  using android::base::EqualsIgnoreCase;
+  if (EqualsIgnoreCase(env_value, "VERBOSE")
+      || env_value == std::to_string((int) VERBOSE)) {
+    return VERBOSE;
+  } else if (EqualsIgnoreCase(env_value, "DEBUG")
+      || env_value == std::to_string((int) DEBUG)) {
+    return DEBUG;
+  } else if (EqualsIgnoreCase(env_value, "INFO")
+      || env_value == std::to_string((int) INFO)) {
+    return INFO;
+  } else if (EqualsIgnoreCase(env_value, "WARNING")
+      || env_value == std::to_string((int) WARNING)) {
+    return WARNING;
+  } else if (EqualsIgnoreCase(env_value, "ERROR")
+      || env_value == std::to_string((int) ERROR)) {
+    return ERROR;
+  } else if (EqualsIgnoreCase(env_value, "FATAL_WITHOUT_ABORT")
+      || env_value == std::to_string((int) FATAL_WITHOUT_ABORT)) {
+    return FATAL_WITHOUT_ABORT;
+  } else if (EqualsIgnoreCase(env_value, "FATAL")
+      || env_value == std::to_string((int) FATAL)) {
+    return FATAL;
+  } else {
+    return default_value;
+  }
+}
+
+LogSeverity ConsoleSeverity() {
+  return GuessSeverity("CF_CONSOLE_SEVERITY", android::base::INFO);
+}
+
+LogSeverity LogFileSeverity() {
+  return GuessSeverity("CF_FILE_SEVERITY", android::base::VERBOSE);
+}
+
+TeeLogger::TeeLogger(const std::vector<SeverityTarget>& destinations)
+    : destinations_(destinations) {
+}
+
+// Copied from system/libbase/logging_splitters.h
+static std::pair<int, int> CountSizeAndNewLines(const char* message) {
+  int size = 0;
+  int new_lines = 0;
+  while (*message != '\0') {
+    size++;
+    if (*message == '\n') {
+      ++new_lines;
+    }
+    ++message;
+  }
+  return {size, new_lines};
+}
+
+// Copied from system/libbase/logging_splitters.h
+// This splits the message up line by line, by calling log_function with a pointer to the start of
+// each line and the size up to the newline character.  It sends size = -1 for the final line.
+template <typename F, typename... Args>
+static void SplitByLines(const char* msg, const F& log_function, Args&&... args) {
+  const char* newline = strchr(msg, '\n');
+  while (newline != nullptr) {
+    log_function(msg, newline - msg, args...);
+    msg = newline + 1;
+    newline = strchr(msg, '\n');
+  }
+
+  log_function(msg, -1, args...);
+}
+
+// Copied from system/libbase/logging_splitters.h
+// This adds the log header to each line of message and returns it as a string intended to be
+// written to stderr.
+static std::string StderrOutputGenerator(const struct tm& now, int pid, uint64_t tid,
+                                         LogSeverity severity, const char* tag, const char* file,
+                                         unsigned int line, const char* message) {
+  char timestamp[32];
+  strftime(timestamp, sizeof(timestamp), "%m-%d %H:%M:%S", &now);
+
+  static const char log_characters[] = "VDIWEFF";
+  static_assert(arraysize(log_characters) - 1 == FATAL + 1,
+                "Mismatch in size of log_characters and values in LogSeverity");
+  char severity_char = log_characters[severity];
+  std::string line_prefix;
+  if (file != nullptr) {
+    line_prefix = StringPrintf("%s %c %s %5d %5" PRIu64 " %s:%u] ", tag ? tag : "nullptr",
+                               severity_char, timestamp, pid, tid, file, line);
+  } else {
+    line_prefix = StringPrintf("%s %c %s %5d %5" PRIu64 " ", tag ? tag : "nullptr", severity_char,
+                               timestamp, pid, tid);
+  }
+
+  auto [size, new_lines] = CountSizeAndNewLines(message);
+  std::string output_string;
+  output_string.reserve(size + new_lines * line_prefix.size() + 1);
+
+  auto concat_lines = [&](const char* message, int size) {
+    output_string.append(line_prefix);
+    if (size == -1) {
+      output_string.append(message);
+    } else {
+      output_string.append(message, size);
+    }
+    output_string.append("\n");
+  };
+  SplitByLines(message, concat_lines);
+  return output_string;
+}
+
+void TeeLogger::operator()(
+    android::base::LogId,
+    android::base::LogSeverity severity,
+    const char* tag,
+    const char* file,
+    unsigned int line,
+    const char* message) {
+  struct tm now;
+  time_t t = time(nullptr);
+  localtime_r(&t, &now);
+  auto output_string =
+      StderrOutputGenerator(
+          now, getpid(), GetThreadId(), severity, tag, file, line, message);
+  for (const auto& destination : destinations_) {
+    if (severity >= destination.severity) {
+      cvd::WriteAll(destination.target, output_string);
+    }
+  }
+}
+
+static std::vector<SeverityTarget> SeverityTargetsForFiles(
+    const std::vector<std::string>& files) {
+  std::vector<SeverityTarget> log_severities;
+  for (const auto& file : files) {
+    auto log_file_fd =
+        cvd::SharedFD::Open(
+          file,
+          O_CREAT | O_WRONLY | O_APPEND,
+          S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+    if (!log_file_fd->IsOpen()) {
+      LOG(FATAL) << "Failed to create log file: " << log_file_fd->StrError();
+    }
+    log_severities.push_back(SeverityTarget {LogFileSeverity(), log_file_fd});
+  }
+  return log_severities;
+}
+
+TeeLogger LogToFiles(const std::vector<std::string>& files) {
+  return TeeLogger(SeverityTargetsForFiles(files));
+}
+
+TeeLogger LogToStderrAndFiles(const std::vector<std::string>& files) {
+  std::vector<SeverityTarget> log_severities = SeverityTargetsForFiles(files);
+  log_severities.push_back(
+      SeverityTarget {ConsoleSeverity(), SharedFD::Dup(/* stderr */ 2)});
+  return TeeLogger(log_severities);
+}
+
+} // namespace cvd
diff --git a/common/libs/utils/tee_logging.h b/common/libs/utils/tee_logging.h
new file mode 100644
index 0000000..09d4963
--- /dev/null
+++ b/common/libs/utils/tee_logging.h
@@ -0,0 +1,54 @@
+//
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include <android-base/logging.h>
+
+#include "common/libs/fs/shared_fd.h"
+
+namespace cvd {
+
+android::base::LogSeverity ConsoleSeverity();
+android::base::LogSeverity LogFileSeverity();
+
+struct SeverityTarget {
+  android::base::LogSeverity severity;
+  cvd::SharedFD target;
+};
+
+class TeeLogger {
+private:
+  std::vector<SeverityTarget> destinations_;
+public:
+  TeeLogger(const std::vector<SeverityTarget>& destinations);
+  ~TeeLogger() = default;
+
+  void operator()(
+      android::base::LogId log_id,
+      android::base::LogSeverity severity,
+      const char* tag,
+      const char* file,
+      unsigned int line,
+      const char* message);
+};
+
+TeeLogger LogToFiles(const std::vector<std::string>& files);
+TeeLogger LogToStderrAndFiles(const std::vector<std::string>& files);
+
+} // namespace cvd
diff --git a/common/libs/utils/users.cpp b/common/libs/utils/users.cpp
index 0ec92c2..cd38982 100644
--- a/common/libs/utils/users.cpp
+++ b/common/libs/utils/users.cpp
@@ -25,7 +25,7 @@
 #include <algorithm>
 #include <vector>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 namespace {
 gid_t GroupIdFromName(const std::string& group_name) {
diff --git a/guest/commands/vsoc_input_service/Android.bp b/guest/commands/vsoc_input_service/Android.bp
index 6c99127..01e07d8 100644
--- a/guest/commands/vsoc_input_service/Android.bp
+++ b/guest/commands/vsoc_input_service/Android.bp
@@ -33,8 +33,5 @@
         "libbase",
         "liblog",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     defaults: ["cuttlefish_guest_only"]
 }
diff --git a/guest/commands/vsoc_input_service/virtual_device_base.cpp b/guest/commands/vsoc_input_service/virtual_device_base.cpp
index 0abb0cd..9adcb95 100644
--- a/guest/commands/vsoc_input_service/virtual_device_base.cpp
+++ b/guest/commands/vsoc_input_service/virtual_device_base.cpp
@@ -16,7 +16,7 @@
 
 #include "virtual_device_base.h"
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <string.h>
diff --git a/guest/commands/vsoc_input_service/vsoc_input_service.cpp b/guest/commands/vsoc_input_service/vsoc_input_service.cpp
index 8b75b45..4e2cc91 100644
--- a/guest/commands/vsoc_input_service/vsoc_input_service.cpp
+++ b/guest/commands/vsoc_input_service/vsoc_input_service.cpp
@@ -24,7 +24,7 @@
 
 #include <gflags/gflags.h>
 #include "log/log.h"
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_fd.h"
 #include "common/libs/device_config/device_config.h"
diff --git a/guest/commands/vsock_logcat/Android.bp b/guest/commands/vsock_logcat/Android.bp
index 52575d7..bebea59 100644
--- a/guest/commands/vsock_logcat/Android.bp
+++ b/guest/commands/vsock_logcat/Android.bp
@@ -29,8 +29,5 @@
     static_libs: [
         "libgflags",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     defaults: ["cuttlefish_guest_only"]
 }
diff --git a/guest/commands/vsock_logcat/main.cpp b/guest/commands/vsock_logcat/main.cpp
index 2abc20b..70c7a50 100644
--- a/guest/commands/vsock_logcat/main.cpp
+++ b/guest/commands/vsock_logcat/main.cpp
@@ -28,7 +28,7 @@
 
 #include <cutils/properties.h>
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_fd.h"
 #include "common/libs/utils/files.h"
diff --git a/guest/monitoring/tombstone_transmit/Android.bp b/guest/monitoring/tombstone_transmit/Android.bp
index 2e0af82..a4739e4 100644
--- a/guest/monitoring/tombstone_transmit/Android.bp
+++ b/guest/monitoring/tombstone_transmit/Android.bp
@@ -28,9 +28,6 @@
         "liblog",
     ],
     stl: "libc++_static",
-    header_libs: [
-        "cuttlefish_glog_product",
-    ],
     defaults: ["cuttlefish_guest_product_only"],
 }
 
diff --git a/host/commands/assemble_cvd/Android.bp b/host/commands/assemble_cvd/Android.bp
index ef77942..0d5a1d7 100644
--- a/host/commands/assemble_cvd/Android.bp
+++ b/host/commands/assemble_cvd/Android.bp
@@ -41,7 +41,6 @@
     ],
     header_libs: [
         "bootimg_headers",
-        "cuttlefish_glog",
     ],
     shared_libs: [
         "cdisk_spec",
diff --git a/host/commands/assemble_cvd/assemble_cvd.cc b/host/commands/assemble_cvd/assemble_cvd.cc
index b45f069..63bc4f7 100644
--- a/host/commands/assemble_cvd/assemble_cvd.cc
+++ b/host/commands/assemble_cvd/assemble_cvd.cc
@@ -16,11 +16,10 @@
 #include <iostream>
 
 #include <android-base/strings.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_buf.h"
 #include "common/libs/fs/shared_fd.h"
-#include "common/libs/fs/tee.h"
 #include "host/commands/assemble_cvd/assembler_defs.h"
 #include "host/commands/assemble_cvd/flags.h"
 #include "host/libs/config/fetcher_config.h"
@@ -46,6 +45,7 @@
 } // namespace
 
 int main(int argc, char** argv) {
+  setenv("ANDROID_LOG_TAGS", "*:v", /* overwrite */ 0);
   ::android::base::InitLogging(argv, android::base::StderrLogger);
 
   if (isatty(0)) {
@@ -61,8 +61,6 @@
     }
   }
 
-  cvd::TeeStderrToFile stderr_tee;
-
   std::string input_files_str;
   {
     auto input_fd = cvd::SharedFD::Dup(0);
@@ -74,10 +72,6 @@
   std::vector<std::string> input_files = android::base::Split(input_files_str, "\n");
 
   auto config = InitFilesystemAndCreateConfig(&argc, &argv, FindFetcherConfig(input_files));
-  auto instance = config->ForDefaultInstance();
-
-  auto assembler_log_path = instance.PerInstancePath("assemble_cvd.log");
-  stderr_tee.SetFile(cvd::SharedFD::Creat(assembler_log_path.c_str(), 0755));
 
   std::cout << GetConfigFilePath(*config) << "\n";
   std::cout << std::flush;
diff --git a/host/commands/assemble_cvd/boot_image_unpacker.cc b/host/commands/assemble_cvd/boot_image_unpacker.cc
index f1ead30..9ea407a 100644
--- a/host/commands/assemble_cvd/boot_image_unpacker.cc
+++ b/host/commands/assemble_cvd/boot_image_unpacker.cc
@@ -22,7 +22,7 @@
 #include <sstream>
 
 #include <bootimg.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/utils/subprocess.h"
 
diff --git a/host/commands/assemble_cvd/data_image.cc b/host/commands/assemble_cvd/data_image.cc
index 4e89ba6..1e6e46d 100644
--- a/host/commands/assemble_cvd/data_image.cc
+++ b/host/commands/assemble_cvd/data_image.cc
@@ -1,6 +1,6 @@
 #include "host/commands/assemble_cvd/data_image.h"
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_buf.h"
 
diff --git a/host/commands/assemble_cvd/flags.cc b/host/commands/assemble_cvd/flags.cc
index d3a4330..f1ce54e 100644
--- a/host/commands/assemble_cvd/flags.cc
+++ b/host/commands/assemble_cvd/flags.cc
@@ -5,6 +5,7 @@
 #include <sys/stat.h>
 #include <sys/statvfs.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #include <algorithm>
 #include <array>
@@ -13,10 +14,11 @@
 
 #include <android-base/strings.h>
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/utils/environment.h"
 #include "common/libs/utils/files.h"
+#include "common/libs/utils/tee_logging.h"
 #include "host/commands/assemble_cvd/boot_image_unpacker.h"
 #include "host/commands/assemble_cvd/data_image.h"
 #include "host/commands/assemble_cvd/image_aggregator.h"
@@ -792,6 +794,10 @@
 
 } // namespace
 
+#ifndef O_TMPFILE
+# define O_TMPFILE (020000000 | O_DIRECTORY)
+#endif
+
 const vsoc::CuttlefishConfig* InitFilesystemAndCreateConfig(
     int* argc, char*** argv, cvd::FetcherConfig fetcher_config) {
   if (!ParseCommandLineFlags(argc, argv)) {
@@ -799,6 +805,28 @@
     exit(AssemblerExitCodes::kArgumentParsingError);
   }
 
+  std::string assembly_dir_parent = cvd::AbsolutePath(FLAGS_assembly_dir);
+  while (assembly_dir_parent[assembly_dir_parent.size() - 1] == '/') {
+    assembly_dir_parent =
+        assembly_dir_parent.substr(0, FLAGS_assembly_dir.rfind('/'));
+  }
+  assembly_dir_parent =
+      assembly_dir_parent.substr(0, FLAGS_assembly_dir.rfind('/'));
+  auto log =
+      cvd::SharedFD::Open(
+          assembly_dir_parent,
+          O_WRONLY | O_TMPFILE,
+          S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+  if (!log->IsOpen()) {
+    LOG(ERROR) << "Could not open O_TMPFILE precursor to assemble_cvd.log: "
+               << log->StrError();
+  } else {
+    android::base::SetLogger(cvd::TeeLogger({
+      {cvd::ConsoleSeverity(), cvd::SharedFD::Dup(2)},
+      {cvd::LogFileSeverity(), log},
+    }));
+  }
+
   auto boot_img_unpacker =
     cvd::BootImageUnpacker::FromImages(FLAGS_boot_image,
                                       FLAGS_vendor_boot_image);
@@ -835,6 +863,11 @@
         exit(AssemblerExitCodes::kAssemblyDirCreationError);
       }
     }
+    if (log->LinkAtCwd(config.AssemblyPath("assemble_cvd.log"))) {
+      LOG(ERROR) << "Unable to persist assemble_cvd log at "
+                  << config.AssemblyPath("assemble_cvd.log")
+                  << ": " << log->StrError();
+    }
     for (const auto& instance : config.Instances()) {
       // Create instance directory if it doesn't exist.
       if (!cvd::DirectoryExists(instance.instance_dir().c_str())) {
diff --git a/host/commands/assemble_cvd/image_aggregator.cc b/host/commands/assemble_cvd/image_aggregator.cc
index f700ccd..5f1c360 100644
--- a/host/commands/assemble_cvd/image_aggregator.cc
+++ b/host/commands/assemble_cvd/image_aggregator.cc
@@ -25,7 +25,7 @@
 #include <string>
 #include <vector>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <json/json.h>
 #include <google/protobuf/text_format.h>
 #include <sparse/sparse.h>
diff --git a/host/commands/assemble_cvd/super_image_mixer.cc b/host/commands/assemble_cvd/super_image_mixer.cc
index 1171126..de6d94c 100644
--- a/host/commands/assemble_cvd/super_image_mixer.cc
+++ b/host/commands/assemble_cvd/super_image_mixer.cc
@@ -24,7 +24,7 @@
 #include <memory>
 
 #include <android-base/strings.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_buf.h"
 #include "common/libs/utils/archive.h"
diff --git a/host/commands/config_server/Android.bp b/host/commands/config_server/Android.bp
index fcf6d39..08dc1fd 100644
--- a/host/commands/config_server/Android.bp
+++ b/host/commands/config_server/Android.bp
@@ -18,9 +18,6 @@
     srcs: [
         "main.cpp",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libbase",
         "libcuttlefish_fs",
diff --git a/host/commands/config_server/main.cpp b/host/commands/config_server/main.cpp
index 6d1e7f8..6db7605 100644
--- a/host/commands/config_server/main.cpp
+++ b/host/commands/config_server/main.cpp
@@ -16,32 +16,29 @@
 
 #include <common/libs/device_config/device_config.h>
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_fd.h"
-#include "host/libs/config/cuttlefish_config.h"
+#include "common/libs/utils/tee_logging.h"
+#include "host/libs/config/logging.h"
 
 DEFINE_int32(
     server_fd, -1,
     "File descriptor to an already created vsock server. Must be specified.");
 
 int main(int argc, char** argv) {
-  ::android::base::InitLogging(argv, android::base::StderrLogger);
+  cvd::DefaultSubprocessLogging(argv);
   google::ParseCommandLineFlags(&argc, &argv, true);
 
-  CHECK(vsoc::CuttlefishConfig::Get()) << "Could not open config";
+  auto device_config = cvd::DeviceConfig::Get();
+
+  CHECK(device_config) << "Could not open device config";
 
   cvd::SharedFD server_fd = cvd::SharedFD::Dup(FLAGS_server_fd);
 
   CHECK(server_fd->IsOpen()) << "Inheriting logcat server: "
                              << server_fd->StrError();
 
-  auto device_config = cvd::DeviceConfig::Get();
-  if (!device_config) {
-    LOG(ERROR) << "Failed to obtain device configuration";
-    return -1;
-  }
-
   // Server loop
   while (true) {
     auto conn = cvd::SharedFD::Accept(*server_fd);
diff --git a/host/commands/console_forwarder/Android.bp b/host/commands/console_forwarder/Android.bp
index a090e98..1a89e2a 100644
--- a/host/commands/console_forwarder/Android.bp
+++ b/host/commands/console_forwarder/Android.bp
@@ -18,9 +18,6 @@
     srcs: [
         "main.cpp",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libbase",
         "libcuttlefish_fs",
diff --git a/host/commands/console_forwarder/main.cpp b/host/commands/console_forwarder/main.cpp
index 1d12b22..f36fd06 100644
--- a/host/commands/console_forwarder/main.cpp
+++ b/host/commands/console_forwarder/main.cpp
@@ -21,11 +21,12 @@
 #include <vector>
 
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <common/libs/fs/shared_fd.h>
 #include <common/libs/fs/shared_select.h>
 #include <host/libs/config/cuttlefish_config.h>
+#include <host/libs/config/logging.h>
 
 DEFINE_int32(console_in_fd,
              -1,
@@ -165,7 +166,7 @@
 };
 
 int main(int argc, char** argv) {
-  ::android::base::InitLogging(argv, android::base::StderrLogger);
+  cvd::DefaultSubprocessLogging(argv);
   ::gflags::ParseCommandLineFlags(&argc, &argv, true);
 
   if (FLAGS_console_in_fd < 0 || FLAGS_console_out_fd < 0) {
diff --git a/host/commands/cvd_status/Android.bp b/host/commands/cvd_status/Android.bp
index 3b1cbbc..9f72e2c 100644
--- a/host/commands/cvd_status/Android.bp
+++ b/host/commands/cvd_status/Android.bp
@@ -18,9 +18,6 @@
     srcs: [
         "cvd_status.cc",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libbase",
         "libcuttlefish_fs",
diff --git a/host/commands/cvd_status/cvd_status.cc b/host/commands/cvd_status/cvd_status.cc
index 5b0513c..7b2789a 100644
--- a/host/commands/cvd_status/cvd_status.cc
+++ b/host/commands/cvd_status/cvd_status.cc
@@ -36,7 +36,7 @@
 #include <vector>
 
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_fd.h"
 #include "common/libs/fs/shared_select.h"
diff --git a/host/commands/fetcher/Android.bp b/host/commands/fetcher/Android.bp
index 1aaf04f..7c1e87f 100644
--- a/host/commands/fetcher/Android.bp
+++ b/host/commands/fetcher/Android.bp
@@ -22,9 +22,6 @@
         "fetch_cvd.cc",
         "install_zip.cc",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     stl: "libc++_static",
     static_libs: [
         "libbase",
diff --git a/host/commands/fetcher/build_api.cc b/host/commands/fetcher/build_api.cc
index 1f3d81b..2722de8 100644
--- a/host/commands/fetcher/build_api.cc
+++ b/host/commands/fetcher/build_api.cc
@@ -24,7 +24,7 @@
 #include <thread>
 
 #include <android-base/strings.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/utils/files.h"
 
diff --git a/host/commands/fetcher/credential_source.cc b/host/commands/fetcher/credential_source.cc
index 89d6b14..2d2873d 100644
--- a/host/commands/fetcher/credential_source.cc
+++ b/host/commands/fetcher/credential_source.cc
@@ -15,7 +15,7 @@
 
 #include "credential_source.h"
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 namespace {
 
diff --git a/host/commands/fetcher/curl_wrapper.cc b/host/commands/fetcher/curl_wrapper.cc
index 472963a..62af912 100644
--- a/host/commands/fetcher/curl_wrapper.cc
+++ b/host/commands/fetcher/curl_wrapper.cc
@@ -19,7 +19,7 @@
 #include <string>
 #include <stdio.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <curl/curl.h>
 #include <json/json.h>
diff --git a/host/commands/fetcher/fetch_cvd.cc b/host/commands/fetcher/fetch_cvd.cc
index 8a15686..42ce875 100644
--- a/host/commands/fetcher/fetch_cvd.cc
+++ b/host/commands/fetcher/fetch_cvd.cc
@@ -21,7 +21,7 @@
 #include <unistd.h>
 
 #include "gflags/gflags.h"
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_fd.h"
 #include "common/libs/utils/archive.h"
diff --git a/host/commands/fetcher/install_zip.cc b/host/commands/fetcher/install_zip.cc
index b3d0e8e..7933000 100644
--- a/host/commands/fetcher/install_zip.cc
+++ b/host/commands/fetcher/install_zip.cc
@@ -21,7 +21,7 @@
 #include <vector>
 
 #include <android-base/strings.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/utils/archive.h"
 #include "common/libs/utils/subprocess.h"
diff --git a/host/commands/kernel_log_monitor/Android.bp b/host/commands/kernel_log_monitor/Android.bp
index 54dda47..9fdd11e 100644
--- a/host/commands/kernel_log_monitor/Android.bp
+++ b/host/commands/kernel_log_monitor/Android.bp
@@ -19,9 +19,6 @@
         "main.cc",
         "kernel_log_server.cc",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libcuttlefish_fs",
         "libcuttlefish_utils",
diff --git a/host/commands/kernel_log_monitor/kernel_log_server.cc b/host/commands/kernel_log_monitor/kernel_log_server.cc
index 4231751..2bc037b 100644
--- a/host/commands/kernel_log_monitor/kernel_log_server.cc
+++ b/host/commands/kernel_log_monitor/kernel_log_server.cc
@@ -19,7 +19,7 @@
 #include <map>
 #include <utility>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <netinet/in.h>
 #include "common/libs/fs/shared_select.h"
 #include "host/libs/config/cuttlefish_config.h"
diff --git a/host/commands/kernel_log_monitor/main.cc b/host/commands/kernel_log_monitor/main.cc
index d7e8fdf..54611a8 100644
--- a/host/commands/kernel_log_monitor/main.cc
+++ b/host/commands/kernel_log_monitor/main.cc
@@ -22,11 +22,12 @@
 
 #include <android-base/strings.h>
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <common/libs/fs/shared_fd.h>
 #include <common/libs/fs/shared_select.h>
 #include <host/libs/config/cuttlefish_config.h>
+#include <host/libs/config/logging.h>
 #include "host/commands/kernel_log_monitor/kernel_log_server.h"
 
 DEFINE_int32(log_pipe_fd, -1,
@@ -60,9 +61,15 @@
 }
 
 int main(int argc, char** argv) {
-  ::android::base::InitLogging(argv, android::base::StderrLogger);
+  cvd::DefaultSubprocessLogging(argv);
   google::ParseCommandLineFlags(&argc, &argv, true);
 
+  auto config = vsoc::CuttlefishConfig::Get();
+
+  CHECK(config) << "Could not open cuttlefish config";
+
+  auto instance = config->ForDefaultInstance();
+
   auto subscriber_fds = SubscribersFromCmdline();
 
   // Disable default handling of SIGPIPE
@@ -71,13 +78,6 @@
   new_action.sa_handler = SIG_IGN;
   sigaction(SIGPIPE, &new_action, &old_action);
 
-  auto config = vsoc::CuttlefishConfig::Get();
-  if (!config) {
-    LOG(ERROR) << "Unable to get config object";
-    return 1;
-  }
-  auto instance = config->ForDefaultInstance();
-
   cvd::SharedFD pipe;
   if (FLAGS_log_pipe_fd < 0) {
     auto log_name = instance.kernel_log_pipe_name();
diff --git a/host/commands/launch/Android.bp b/host/commands/launch/Android.bp
index dafe990..53ed2c3 100644
--- a/host/commands/launch/Android.bp
+++ b/host/commands/launch/Android.bp
@@ -20,9 +20,6 @@
         "flag_forwarder.cc",
         "launch_cvd.cc",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libcuttlefish_fs",
         "libcuttlefish_utils",
diff --git a/host/commands/launch/filesystem_explorer.cc b/host/commands/launch/filesystem_explorer.cc
index 4d43dcf..12cd1ed 100644
--- a/host/commands/launch/filesystem_explorer.cc
+++ b/host/commands/launch/filesystem_explorer.cc
@@ -22,7 +22,7 @@
 #include <errno.h>
 #include <sys/types.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/utils/files.h"
 #include "common/libs/utils/environment.h"
diff --git a/host/commands/launch/flag_forwarder.cc b/host/commands/launch/flag_forwarder.cc
index 9e639e4..8dc92d0 100644
--- a/host/commands/launch/flag_forwarder.cc
+++ b/host/commands/launch/flag_forwarder.cc
@@ -23,7 +23,7 @@
 #include <vector>
 
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <libxml/tree.h>
 
 #include "common/libs/fs/shared_buf.h"
diff --git a/host/commands/launch/launch_cvd.cc b/host/commands/launch/launch_cvd.cc
index 6cc7c93..f375e83 100644
--- a/host/commands/launch/launch_cvd.cc
+++ b/host/commands/launch/launch_cvd.cc
@@ -16,7 +16,7 @@
 #include <sstream>
 
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_buf.h"
 #include "common/libs/fs/shared_fd.h"
@@ -40,6 +40,8 @@
 DEFINE_bool(run_file_discovery, true,
             "Whether to run file discovery or get input files from stdin.");
 DEFINE_int32(num_instances, 1, "Number of Android guests to launch");
+DEFINE_string(verbosity, "INFO", "Console logging verbosity. Options are VERBOSE,"
+                                 "DEBUG,INFO,WARNING,ERROR");
 
 namespace {
 
@@ -96,6 +98,8 @@
 
   gflags::HandleCommandLineHelpFlags();
 
+  setenv("CF_CONSOLE_SEVERITY", FLAGS_verbosity.c_str(), /* replace */ false);
+
   cvd::SharedFD assembler_stdout, assembler_stdout_capture;
   cvd::SharedFD::Pipe(&assembler_stdout_capture, &assembler_stdout);
 
diff --git a/host/commands/log_tee/Android.bp b/host/commands/log_tee/Android.bp
new file mode 100644
index 0000000..567009a
--- /dev/null
+++ b/host/commands/log_tee/Android.bp
@@ -0,0 +1,35 @@
+//
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_binary_host {
+    name: "log_tee",
+    srcs: [
+        "log_tee.cpp",
+    ],
+    shared_libs: [
+        "libcuttlefish_fs",
+        "libcuttlefish_utils",
+        "libbase",
+        "libnl",
+    ],
+    static_libs: [
+        "libgflags",
+        "libcuttlefish_host_config",
+        "libcuttlefish_vm_manager",
+        "libxml2",
+        "libjsoncpp",
+    ],
+    defaults: ["cuttlefish_host_only", "cuttlefish_libicuuc"],
+}
diff --git a/host/commands/log_tee/log_tee.cpp b/host/commands/log_tee/log_tee.cpp
new file mode 100644
index 0000000..c1b3ba0
--- /dev/null
+++ b/host/commands/log_tee/log_tee.cpp
@@ -0,0 +1,72 @@
+//
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <android-base/logging.h>
+#include <android-base/strings.h>
+#include <gflags/gflags.h>
+
+#include "common/libs/fs/shared_fd.h"
+#include "common/libs/utils/tee_logging.h"
+#include "host/libs/config/cuttlefish_config.h"
+
+DEFINE_string(process_name, "", "The process to credit log messages to");
+DEFINE_int32(log_fd_in, -1, "The file descriptor to read logs from.");
+
+int main(int argc, char** argv) {
+  ::android::base::InitLogging(argv, android::base::StderrLogger);
+  google::ParseCommandLineFlags(&argc, &argv, /* remove_flags */ true);
+
+  CHECK(FLAGS_log_fd_in >= 0) << "-log_fd_in is required";
+
+  auto config = vsoc::CuttlefishConfig::Get();
+
+  CHECK(config) << "Could not open cuttlefish config";
+
+  auto instance = config->ForDefaultInstance();
+
+  if (config->run_as_daemon()) {
+    android::base::SetLogger(
+        cvd::LogToFiles({instance.launcher_log_path()}));
+  } else {
+    android::base::SetLogger(
+        cvd::LogToStderrAndFiles({instance.launcher_log_path()}));
+  }
+
+  auto log_fd = cvd::SharedFD::Dup(FLAGS_log_fd_in);
+  CHECK(log_fd->IsOpen()) << "Failed to dup log_fd_in: " <<  log_fd->StrError();
+  close(FLAGS_log_fd_in);
+
+  if (FLAGS_process_name.size() > 0) {
+    android::base::SetDefaultTag(FLAGS_process_name);
+  }
+
+  char buf[1 << 16];
+  ssize_t chars_read = 0;
+
+  LOG(DEBUG) << "Starting to read from process " << FLAGS_process_name;
+
+  while ((chars_read = log_fd->Read(buf, sizeof(buf))) > 0) {
+    auto trimmed = android::base::Trim(std::string(buf, chars_read));
+    // Newlines inside `trimmed` are handled by the android logging code.
+    LOG(INFO) << trimmed;
+  }
+
+  if (chars_read < 0) {
+    LOG(DEBUG) << "Failed to read from process " << FLAGS_process_name << ": "
+               << log_fd->StrError();
+  }
+
+  LOG(DEBUG) << "Finished reading from process " << FLAGS_process_name;
+}
diff --git a/host/commands/logcat_receiver/Android.bp b/host/commands/logcat_receiver/Android.bp
index 72438c7..086d41e 100644
--- a/host/commands/logcat_receiver/Android.bp
+++ b/host/commands/logcat_receiver/Android.bp
@@ -18,9 +18,6 @@
     srcs: [
         "main.cpp",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libbase",
         "libcuttlefish_fs",
diff --git a/host/commands/logcat_receiver/main.cpp b/host/commands/logcat_receiver/main.cpp
index e07e3ec..c4a0a9a 100644
--- a/host/commands/logcat_receiver/main.cpp
+++ b/host/commands/logcat_receiver/main.cpp
@@ -15,17 +15,18 @@
  */
 
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_fd.h"
 #include "host/libs/config/cuttlefish_config.h"
+#include "host/libs/config/logging.h"
 
 DEFINE_int32(
     server_fd, -1,
     "File descriptor to an already created vsock server. Must be specified.");
 
 int main(int argc, char** argv) {
-  ::android::base::InitLogging(argv, android::base::StderrLogger);
+  cvd::DefaultSubprocessLogging(argv);
   google::ParseCommandLineFlags(&argc, &argv, true);
 
   auto config = vsoc::CuttlefishConfig::Get();
diff --git a/host/commands/run_cvd/Android.bp b/host/commands/run_cvd/Android.bp
index c338f08..2afc59c 100644
--- a/host/commands/run_cvd/Android.bp
+++ b/host/commands/run_cvd/Android.bp
@@ -21,9 +21,6 @@
         "main.cc",
         "process_monitor.cc",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libcuttlefish_fs",
         "libcuttlefish_utils",
diff --git a/host/commands/run_cvd/launch.cc b/host/commands/run_cvd/launch.cc
index 5ae66a9..3cc1f77 100644
--- a/host/commands/run_cvd/launch.cc
+++ b/host/commands/run_cvd/launch.cc
@@ -3,7 +3,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_fd.h"
 #include "common/libs/utils/files.h"
diff --git a/host/commands/run_cvd/main.cc b/host/commands/run_cvd/main.cc
index b45b22c..ad684e3 100644
--- a/host/commands/run_cvd/main.cc
+++ b/host/commands/run_cvd/main.cc
@@ -37,18 +37,18 @@
 
 #include <android-base/strings.h>
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_buf.h"
 #include "common/libs/fs/shared_fd.h"
 #include "common/libs/fs/shared_select.h"
-#include "common/libs/fs/tee.h"
 #include "common/libs/utils/environment.h"
 #include "common/libs/utils/files.h"
 #include "common/libs/utils/network.h"
 #include "common/libs/utils/subprocess.h"
 #include "common/libs/utils/size_utils.h"
 #include "host/commands/run_cvd/kernel_args.h"
+#include "common/libs/utils/tee_logging.h"
 #include "host/commands/run_cvd/launch.h"
 #include "host/commands/run_cvd/runner_defs.h"
 #include "host/commands/run_cvd/process_monitor.h"
@@ -209,12 +209,15 @@
     // Redirect standard I/O
     auto log_path = instance.launcher_log_path();
     auto log =
-        cvd::SharedFD::Open(log_path.c_str(), O_CREAT | O_WRONLY | O_TRUNC,
+        cvd::SharedFD::Open(log_path.c_str(), O_CREAT | O_WRONLY | O_APPEND,
                             S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
     if (!log->IsOpen()) {
       LOG(ERROR) << "Failed to create launcher log file: " << log->StrError();
       std::exit(RunnerExitCodes::kDaemonizationError);
     }
+    ::android::base::SetLogger(cvd::TeeLogger({
+      {cvd::LogFileSeverity(), log},
+    }));
     auto dev_null = cvd::SharedFD::Open("/dev/null", O_RDONLY);
     if (!dev_null->IsOpen()) {
       LOG(ERROR) << "Failed to open /dev/null: " << dev_null->StrError();
@@ -280,6 +283,7 @@
 }  // namespace
 
 int main(int argc, char** argv) {
+  setenv("ANDROID_LOG_TAGS", "*:v", /* overwrite */ 0);
   ::android::base::InitLogging(argv, android::base::StderrLogger);
   google::ParseCommandLineFlags(&argc, &argv, false);
 
@@ -296,8 +300,6 @@
     }
   }
 
-  cvd::TeeStderrToFile stderr_tee;
-
   std::string input_files_str;
   {
     auto input_fd = cvd::SharedFD::Dup(0);
@@ -321,8 +323,14 @@
   auto config = vsoc::CuttlefishConfig::Get();
   auto instance = config->ForDefaultInstance();
 
-  auto runner_log_path = instance.PerInstancePath("run_cvd.log");
-  stderr_tee.SetFile(cvd::SharedFD::Creat(runner_log_path.c_str(), 0755));
+  auto log_path = instance.launcher_log_path();
+
+  {
+    std::ofstream launcher_log_ofstream(log_path.c_str());
+    auto assemble_log = cvd::ReadFile(config->AssemblyPath("assemble_cvd.log"));
+    launcher_log_ofstream << assemble_log;
+  }
+  ::android::base::SetLogger(cvd::LogToStderrAndFiles({log_path}));
 
   // Change working directory to the instance directory as early as possible to
   // ensure all host processes have the same working dir. This helps stop_cvd
diff --git a/host/commands/run_cvd/process_monitor.cc b/host/commands/run_cvd/process_monitor.cc
index 93b6881..e1b2761 100644
--- a/host/commands/run_cvd/process_monitor.cc
+++ b/host/commands/run_cvd/process_monitor.cc
@@ -24,7 +24,7 @@
 
 #include <map>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_select.h"
 #include "host/commands/run_cvd/process_monitor.h"
diff --git a/host/commands/stop_cvd/Android.bp b/host/commands/stop_cvd/Android.bp
index ad279bb..8c95d83 100644
--- a/host/commands/stop_cvd/Android.bp
+++ b/host/commands/stop_cvd/Android.bp
@@ -18,9 +18,6 @@
     srcs: [
         "main.cc",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libbase",
         "libcuttlefish_fs",
diff --git a/host/commands/stop_cvd/main.cc b/host/commands/stop_cvd/main.cc
index 65dbeb7..5736561 100644
--- a/host/commands/stop_cvd/main.cc
+++ b/host/commands/stop_cvd/main.cc
@@ -38,7 +38,7 @@
 
 #include <android-base/strings.h>
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_fd.h"
 #include "common/libs/fs/shared_select.h"
diff --git a/host/commands/tombstone_receiver/Android.bp b/host/commands/tombstone_receiver/Android.bp
index 66a353a..9fed4e2 100644
--- a/host/commands/tombstone_receiver/Android.bp
+++ b/host/commands/tombstone_receiver/Android.bp
@@ -18,9 +18,6 @@
     srcs: [
         "main.cpp",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libbase",
         "libcuttlefish_fs",
@@ -28,6 +25,8 @@
         "libcuttlefish_utils",
     ],
     static_libs: [
+        "libcuttlefish_host_config",
+        "libjsoncpp",
         "libgflags",
     ],
     defaults: ["cuttlefish_host_only"],
diff --git a/host/commands/tombstone_receiver/main.cpp b/host/commands/tombstone_receiver/main.cpp
index 25da1a3..a84761e 100644
--- a/host/commands/tombstone_receiver/main.cpp
+++ b/host/commands/tombstone_receiver/main.cpp
@@ -15,13 +15,14 @@
  */
 
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <chrono>
 #include <fstream>
 #include <iomanip>
 #include <sstream>
 
+#include "host/libs/config/logging.h"
 #include "common/libs/fs/shared_fd.h"
 
 DEFINE_int32(
@@ -55,7 +56,7 @@
 
 #define CHUNK_RECV_MAX_LEN (1024)
 int main(int argc, char** argv) {
-  ::android::base::InitLogging(argv, android::base::StderrLogger);
+  cvd::DefaultSubprocessLogging(argv);
   google::ParseCommandLineFlags(&argc, &argv, true);
 
   cvd::SharedFD server_fd = cvd::SharedFD::Dup(FLAGS_server_fd);
diff --git a/host/frontend/adb_connector/Android.bp b/host/frontend/adb_connector/Android.bp
index c0f04cd..a2cf3c6 100644
--- a/host/frontend/adb_connector/Android.bp
+++ b/host/frontend/adb_connector/Android.bp
@@ -19,15 +19,15 @@
         "adb_connection_maintainer.cpp",
         "main.cpp"
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     static_libs: [
+        "libcuttlefish_host_config",
         "libgflags",
+        "libjsoncpp",
     ],
     shared_libs: [
         "libbase",
         "libcuttlefish_fs",
+        "libcuttlefish_utils",
         "liblog",
     ],
     defaults: ["cuttlefish_host_only"],
diff --git a/host/frontend/adb_connector/adb_connection_maintainer.cpp b/host/frontend/adb_connector/adb_connection_maintainer.cpp
index 6b60e34..625071b 100644
--- a/host/frontend/adb_connector/adb_connection_maintainer.cpp
+++ b/host/frontend/adb_connector/adb_connection_maintainer.cpp
@@ -20,7 +20,7 @@
 #include <string>
 #include <memory>
 #include <vector>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <unistd.h>
 
diff --git a/host/frontend/adb_connector/main.cpp b/host/frontend/adb_connector/main.cpp
index a6f8ebe..2e27d3e 100644
--- a/host/frontend/adb_connector/main.cpp
+++ b/host/frontend/adb_connector/main.cpp
@@ -21,7 +21,7 @@
 #include <thread>
 #include <vector>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <gflags/gflags.h>
 
 #include <unistd.h>
@@ -30,6 +30,7 @@
 #include "common/libs/fs/shared_fd.h"
 #include "host/frontend/adb_connector/adb_connection_maintainer.h"
 #include "host/libs/config/cuttlefish_config.h"
+#include "host/libs/config/logging.h"
 
 DEFINE_string(addresses, "", "Comma-separated list of addresses to "
                              "'adb connect' to");
@@ -77,6 +78,7 @@
 }  // namespace
 
 int main(int argc, char* argv[]) {
+  cvd::DefaultSubprocessLogging(argv);
   gflags::ParseCommandLineFlags(&argc, &argv, true);
   CHECK(!FLAGS_addresses.empty()) << "Must specify --addresses flag";
 
diff --git a/host/frontend/gcastv2/https/Android.bp b/host/frontend/gcastv2/https/Android.bp
index e4d135a..4078e80 100644
--- a/host/frontend/gcastv2/https/Android.bp
+++ b/host/frontend/gcastv2/https/Android.bp
@@ -31,9 +31,6 @@
         "Support.cpp",
     ],
     defaults: ["cuttlefish_host_only"],
-    header_libs: [
-	"cuttlefish_glog",
-    ],
     shared_libs: [
         "libbase",
         "libcrypto",
diff --git a/host/frontend/gcastv2/https/ClientSocket.cpp b/host/frontend/gcastv2/https/ClientSocket.cpp
index 8529461..6e2a8ad 100644
--- a/host/frontend/gcastv2/https/ClientSocket.cpp
+++ b/host/frontend/gcastv2/https/ClientSocket.cpp
@@ -21,7 +21,7 @@
 #include <https/SafeCallbackable.h>
 #include <https/ServerSocket.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <cstdlib>
 
diff --git a/host/frontend/gcastv2/https/HTTPClientConnection.cpp b/host/frontend/gcastv2/https/HTTPClientConnection.cpp
index cc29c6e..95e3d7c 100644
--- a/host/frontend/gcastv2/https/HTTPClientConnection.cpp
+++ b/host/frontend/gcastv2/https/HTTPClientConnection.cpp
@@ -24,7 +24,7 @@
 
 #include <https/Support.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <arpa/inet.h>
 #include <cerrno>
diff --git a/host/frontend/gcastv2/https/HTTPServer.cpp b/host/frontend/gcastv2/https/HTTPServer.cpp
index 1a40420..967f5f7 100644
--- a/host/frontend/gcastv2/https/HTTPServer.cpp
+++ b/host/frontend/gcastv2/https/HTTPServer.cpp
@@ -20,7 +20,7 @@
 #include <https/HTTPRequestResponse.h>
 #include <https/Support.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <iostream>
 #include <map>
diff --git a/host/frontend/gcastv2/https/RunLoop.cpp b/host/frontend/gcastv2/https/RunLoop.cpp
index 9027343..f9d50c6 100644
--- a/host/frontend/gcastv2/https/RunLoop.cpp
+++ b/host/frontend/gcastv2/https/RunLoop.cpp
@@ -18,7 +18,7 @@
 
 #include <https/Support.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <cstring>
 #include <fcntl.h>
diff --git a/host/frontend/gcastv2/https/SSLSocket.cpp b/host/frontend/gcastv2/https/SSLSocket.cpp
index 38ad1c4..db8543a 100644
--- a/host/frontend/gcastv2/https/SSLSocket.cpp
+++ b/host/frontend/gcastv2/https/SSLSocket.cpp
@@ -18,7 +18,7 @@
 
 #include <https/SafeCallbackable.h>
 #include <https/Support.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <sstream>
 #include <sys/socket.h>
 
diff --git a/host/frontend/gcastv2/https/ServerSocket.cpp b/host/frontend/gcastv2/https/ServerSocket.cpp
index 8928475..1f95018 100644
--- a/host/frontend/gcastv2/https/ServerSocket.cpp
+++ b/host/frontend/gcastv2/https/ServerSocket.cpp
@@ -21,7 +21,7 @@
 #include <https/SafeCallbackable.h>
 #include <https/Support.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include <arpa/inet.h>
 #include <fcntl.h>
diff --git a/host/frontend/gcastv2/libsource/Android.bp b/host/frontend/gcastv2/libsource/Android.bp
index 671e4ba..70af4e0 100644
--- a/host/frontend/gcastv2/libsource/Android.bp
+++ b/host/frontend/gcastv2/libsource/Android.bp
@@ -23,9 +23,6 @@
         "HostToGuestComms.cpp",
         "StreamingSource.cpp",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libbase",
         "libyuv",
diff --git a/host/frontend/gcastv2/libsource/InputSink.cpp b/host/frontend/gcastv2/libsource/InputSink.cpp
index ce9597d..d72ca68 100644
--- a/host/frontend/gcastv2/libsource/InputSink.cpp
+++ b/host/frontend/gcastv2/libsource/InputSink.cpp
@@ -23,7 +23,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <https/SafeCallbackable.h>
 #include <https/Support.h>
 
diff --git a/host/frontend/gcastv2/libsource/KeyboardSink.cpp b/host/frontend/gcastv2/libsource/KeyboardSink.cpp
index 526ade3..cf19b38 100644
--- a/host/frontend/gcastv2/libsource/KeyboardSink.cpp
+++ b/host/frontend/gcastv2/libsource/KeyboardSink.cpp
@@ -18,7 +18,7 @@
 
 #include <linux/input.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 namespace android {
 
diff --git a/host/frontend/gcastv2/webrtc/Android.bp b/host/frontend/gcastv2/webrtc/Android.bp
index c1d99f0..b0c775c 100644
--- a/host/frontend/gcastv2/webrtc/Android.bp
+++ b/host/frontend/gcastv2/webrtc/Android.bp
@@ -53,9 +53,6 @@
         "libbase",
         "libcuttlefish_fs",
     ],
-    header_libs: [
-        "cuttlefish_common_headers",
-    ],
     defaults: ["cuttlefish_host_only"],
     local_include_dirs: ["include"],
     export_include_dirs: ["include"],
@@ -66,9 +63,6 @@
     srcs: [
         "webRTC.cpp",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libbase",
         "libcrypto",
diff --git a/host/frontend/gcastv2/webrtc/webRTC.cpp b/host/frontend/gcastv2/webrtc/webRTC.cpp
index c8afbee..12f977b 100644
--- a/host/frontend/gcastv2/webrtc/webRTC.cpp
+++ b/host/frontend/gcastv2/webrtc/webRTC.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <host/libs/config/logging.h>
+
 #include "Utils.h"
 
 #include <webrtc/AdbWebSocketHandler.h>
@@ -66,6 +68,7 @@
         "host:port of STUN server to use for public address resolution");
 
 int main(int argc, char **argv) {
+    cvd::DefaultSubprocessLogging(argv);
     ::gflags::ParseCommandLineFlags(&argc, &argv, true);
 
     SSLSocket::Init();
diff --git a/host/frontend/vnc_server/Android.bp b/host/frontend/vnc_server/Android.bp
index 3df8d5f..68fae32 100644
--- a/host/frontend/vnc_server/Android.bp
+++ b/host/frontend/vnc_server/Android.bp
@@ -25,9 +25,6 @@
         "vnc_client_connection.cpp",
         "vnc_server.cpp",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libcuttlefish_fs",
         "libcuttlefish_utils",
diff --git a/host/frontend/vnc_server/blackboard.cpp b/host/frontend/vnc_server/blackboard.cpp
index b842648..0790b49 100644
--- a/host/frontend/vnc_server/blackboard.cpp
+++ b/host/frontend/vnc_server/blackboard.cpp
@@ -20,7 +20,7 @@
 #include <utility>
 
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include "host/frontend/vnc_server/frame_buffer_watcher.h"
 
 DEFINE_bool(debug_blackboard, false,
diff --git a/host/frontend/vnc_server/frame_buffer_watcher.cpp b/host/frontend/vnc_server/frame_buffer_watcher.cpp
index 126fb6b..02f1d6e 100644
--- a/host/frontend/vnc_server/frame_buffer_watcher.cpp
+++ b/host/frontend/vnc_server/frame_buffer_watcher.cpp
@@ -25,7 +25,7 @@
 #include <thread>
 #include <utility>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include "host/frontend/vnc_server/vnc_utils.h"
 #include "host/libs/screen_connector/screen_connector.h"
 
diff --git a/host/frontend/vnc_server/jpeg_compressor.cpp b/host/frontend/vnc_server/jpeg_compressor.cpp
index 3bd3753..270283e 100644
--- a/host/frontend/vnc_server/jpeg_compressor.cpp
+++ b/host/frontend/vnc_server/jpeg_compressor.cpp
@@ -17,7 +17,7 @@
 #include <stdio.h>  // stdio.h must appear before jpeglib.h
 #include <jpeglib.h>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include "host/frontend/vnc_server/jpeg_compressor.h"
 #include "host/frontend/vnc_server/vnc_utils.h"
 #include "host/libs/screen_connector/screen_connector.h"
diff --git a/host/frontend/vnc_server/main.cpp b/host/frontend/vnc_server/main.cpp
index eab7011..add9474 100644
--- a/host/frontend/vnc_server/main.cpp
+++ b/host/frontend/vnc_server/main.cpp
@@ -19,18 +19,17 @@
 
 #include <gflags/gflags.h>
 
-#include "common/libs/glog/logging.h"
 #include "host/frontend/vnc_server/vnc_server.h"
 #include "host/frontend/vnc_server/vnc_utils.h"
-#include "host/libs/config/cuttlefish_config.h"
+#include "host/libs/config/logging.h"
 
 DEFINE_bool(agressive, false, "Whether to use agressive server");
 DEFINE_int32(port, 6444, "Port where to listen for connections");
 
 int main(int argc, char* argv[]) {
-  using ::android::base::ERROR;
-  ::android::base::InitLogging(argv, android::base::StderrLogger);
-  ::gflags::ParseCommandLineFlags(&argc, &argv, true);
+  cvd::DefaultSubprocessLogging(argv);
+  google::ParseCommandLineFlags(&argc, &argv, true);
+
   cvd::vnc::VncServer vnc_server(FLAGS_port, FLAGS_agressive);
   vnc_server.MainLoop();
 }
diff --git a/host/frontend/vnc_server/virtual_inputs.cpp b/host/frontend/vnc_server/virtual_inputs.cpp
index fb91409..444136c 100644
--- a/host/frontend/vnc_server/virtual_inputs.cpp
+++ b/host/frontend/vnc_server/virtual_inputs.cpp
@@ -16,7 +16,7 @@
 
 #include "host/frontend/vnc_server/virtual_inputs.h"
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <linux/input.h>
 #include <linux/uinput.h>
 
diff --git a/host/frontend/vnc_server/vnc_client_connection.cpp b/host/frontend/vnc_server/vnc_client_connection.cpp
index c15d46c..8e2e32c 100644
--- a/host/frontend/vnc_server/vnc_client_connection.cpp
+++ b/host/frontend/vnc_server/vnc_client_connection.cpp
@@ -31,7 +31,7 @@
 #include <vector>
 
 #include <gflags/gflags.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include "common/libs/tcp_socket/tcp_socket.h"
 #include "host/frontend/vnc_server/keysyms.h"
 #include "host/frontend/vnc_server/mocks.h"
diff --git a/host/frontend/vnc_server/vnc_server.cpp b/host/frontend/vnc_server/vnc_server.cpp
index 3aba467..84e1d8b 100644
--- a/host/frontend/vnc_server/vnc_server.cpp
+++ b/host/frontend/vnc_server/vnc_server.cpp
@@ -16,7 +16,7 @@
 
 #include "host/frontend/vnc_server/vnc_server.h"
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include "common/libs/tcp_socket/tcp_socket.h"
 #include "host/frontend/vnc_server/blackboard.h"
 #include "host/frontend/vnc_server/frame_buffer_watcher.h"
diff --git a/host/libs/config/Android.bp b/host/libs/config/Android.bp
index d88b206..e6e91b7 100644
--- a/host/libs/config/Android.bp
+++ b/host/libs/config/Android.bp
@@ -18,9 +18,7 @@
     srcs: [
         "cuttlefish_config.cpp",
         "fetcher_config.cpp",
-    ],
-    header_libs: [
-        "cuttlefish_glog",
+        "logging.cpp",
     ],
     shared_libs: [
         "libcuttlefish_fs",
diff --git a/host/libs/config/cuttlefish_config.cpp b/host/libs/config/cuttlefish_config.cpp
index 1c561be..d069e66 100644
--- a/host/libs/config/cuttlefish_config.cpp
+++ b/host/libs/config/cuttlefish_config.cpp
@@ -28,7 +28,7 @@
 #include <time.h>
 
 #include <android-base/strings.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <json/json.h>
 
 #include "common/libs/utils/environment.h"
diff --git a/host/libs/config/logging.cpp b/host/libs/config/logging.cpp
new file mode 100644
index 0000000..7ff88c7
--- /dev/null
+++ b/host/libs/config/logging.cpp
@@ -0,0 +1,43 @@
+//
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "logging.h"
+
+#include <android-base/logging.h>
+
+#include "common/libs/utils/tee_logging.h"
+#include "host/libs/config/cuttlefish_config.h"
+
+using android::base::SetLogger;
+
+namespace cvd {
+
+void DefaultSubprocessLogging(char* argv[]) {
+  ::android::base::InitLogging(argv, android::base::StderrLogger);
+
+  auto config = vsoc::CuttlefishConfig::Get();
+
+  CHECK(config) << "Could not open cuttlefish config";
+
+  auto instance = config->ForDefaultInstance();
+
+  if (config->run_as_daemon()) {
+    SetLogger(LogToFiles({instance.launcher_log_path()}));
+  } else {
+    SetLogger(LogToStderrAndFiles({instance.launcher_log_path()}));
+  }
+}
+
+} // namespace cvd
diff --git a/host/libs/config/logging.h b/host/libs/config/logging.h
new file mode 100644
index 0000000..f66ed1e
--- /dev/null
+++ b/host/libs/config/logging.h
@@ -0,0 +1,22 @@
+//
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma once
+
+namespace cvd {
+
+void DefaultSubprocessLogging(char* argv[]);
+
+} // namespace cvd
diff --git a/host/libs/screen_connector/Android.bp b/host/libs/screen_connector/Android.bp
index 69fa002..74bc936 100644
--- a/host/libs/screen_connector/Android.bp
+++ b/host/libs/screen_connector/Android.bp
@@ -20,9 +20,6 @@
         "socket_based_screen_connector.cpp",
         "wayland_screen_connector.cpp",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libcuttlefish_fs",
         "libbase",
diff --git a/host/libs/screen_connector/screen_connector.cpp b/host/libs/screen_connector/screen_connector.cpp
index 39c0fa3..132a894 100644
--- a/host/libs/screen_connector/screen_connector.cpp
+++ b/host/libs/screen_connector/screen_connector.cpp
@@ -16,7 +16,7 @@
 
 #include "host/libs/screen_connector/screen_connector.h"
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "host/libs/config/cuttlefish_config.h"
 #include "host/libs/screen_connector/socket_based_screen_connector.h"
diff --git a/host/libs/screen_connector/socket_based_screen_connector.cpp b/host/libs/screen_connector/socket_based_screen_connector.cpp
index 7e6333a..4630ebb 100644
--- a/host/libs/screen_connector/socket_based_screen_connector.cpp
+++ b/host/libs/screen_connector/socket_based_screen_connector.cpp
@@ -16,7 +16,7 @@
 
 #include "host/libs/screen_connector/socket_based_screen_connector.h"
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_fd.h"
 
diff --git a/host/libs/screen_connector/wayland_screen_connector.cpp b/host/libs/screen_connector/wayland_screen_connector.cpp
index 8059290..4725e85 100644
--- a/host/libs/screen_connector/wayland_screen_connector.cpp
+++ b/host/libs/screen_connector/wayland_screen_connector.cpp
@@ -21,7 +21,7 @@
 
 #include <future>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "host/libs/wayland/wayland_server.h"
 
diff --git a/host/libs/vm_manager/Android.bp b/host/libs/vm_manager/Android.bp
index 734dfe5..71ca11c 100644
--- a/host/libs/vm_manager/Android.bp
+++ b/host/libs/vm_manager/Android.bp
@@ -20,9 +20,6 @@
         "qemu_manager.cpp",
         "vm_manager.cpp",
     ],
-    header_libs: [
-        "cuttlefish_glog",
-    ],
     shared_libs: [
         "libcuttlefish_fs",
         "libcuttlefish_utils",
diff --git a/host/libs/vm_manager/crosvm_manager.cpp b/host/libs/vm_manager/crosvm_manager.cpp
index 7fecc34..ad78cbf 100644
--- a/host/libs/vm_manager/crosvm_manager.cpp
+++ b/host/libs/vm_manager/crosvm_manager.cpp
@@ -23,7 +23,7 @@
 #include <vector>
 
 #include <android-base/strings.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/utils/environment.h"
 #include "common/libs/utils/network.h"
@@ -217,12 +217,28 @@
   console_cmd.AddParameter("--console_in_fd=", console_in_wr);
   console_cmd.AddParameter("--console_out_fd=", console_out_rd);
 
+  cvd::SharedFD log_out_rd, log_out_wr;
+  if (!cvd::SharedFD::Pipe(&log_out_rd, &log_out_wr)) {
+    LOG(ERROR) << "Failed to create log pipe for crosvm's stdout/stderr: "
+               << console_in_rd->StrError();
+    return {};
+  }
+  crosvm_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut,
+                           log_out_wr);
+  crosvm_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdErr,
+                           log_out_wr);
+
+  cvd::Command log_tee_cmd(vsoc::DefaultHostArtifactsPath("bin/log_tee"));
+  log_tee_cmd.AddParameter("--process_name=crosvm");
+  log_tee_cmd.AddParameter("--log_fd_in=", log_out_rd);
+
   // This needs to be the last parameter
   crosvm_cmd.AddParameter(config_->GetKernelImageToUse());
 
   std::vector<cvd::Command> ret;
   ret.push_back(std::move(crosvm_cmd));
   ret.push_back(std::move(console_cmd));
+  ret.push_back(std::move(log_tee_cmd));
   return ret;
 }
 
diff --git a/host/libs/vm_manager/qemu_manager.cpp b/host/libs/vm_manager/qemu_manager.cpp
index cfc073c..f08d66c 100644
--- a/host/libs/vm_manager/qemu_manager.cpp
+++ b/host/libs/vm_manager/qemu_manager.cpp
@@ -31,7 +31,7 @@
 #include <vector>
 
 #include <android-base/strings.h>
-#include <glog/logging.h>
+#include <android-base/logging.h>
 
 #include "common/libs/fs/shared_select.h"
 #include "common/libs/utils/files.h"
diff --git a/host/libs/vm_manager/vm_manager.cpp b/host/libs/vm_manager/vm_manager.cpp
index d2810da..ceea865 100644
--- a/host/libs/vm_manager/vm_manager.cpp
+++ b/host/libs/vm_manager/vm_manager.cpp
@@ -18,7 +18,7 @@
 
 #include <memory>
 
-#include <glog/logging.h>
+#include <android-base/logging.h>
 #include <sys/utsname.h>
 
 #include "common/libs/utils/users.h"
diff --git a/host_package.mk b/host_package.mk
index 6a2ba84..7d8c41b 100644
--- a/host_package.mk
+++ b/host_package.mk
@@ -58,6 +58,7 @@
     make_f2fs \
     tapsetiff \
     newfs_msdos \
+    log_tee \
 
 ifneq ($(wildcard device/google/trout),)
     cvd_host_executables += android.hardware.automotive.vehicle@2.0-virtualization-grpc-server
diff --git a/tools/play_audio/client_socket.cpp b/tools/play_audio/client_socket.cpp
index 97c6b13..dbc3db7 100644
--- a/tools/play_audio/client_socket.cpp
+++ b/tools/play_audio/client_socket.cpp
@@ -16,7 +16,7 @@
  */
 #include "client_socket.h"
 
-#include "glog/logging.h"
+#include "android-base/logging.h"
 
 #include <arpa/inet.h>
 #include <netinet/in.h>
diff --git a/tools/play_audio/play_audio.cpp b/tools/play_audio/play_audio.cpp
index 2594396..64c2a10 100644
--- a/tools/play_audio/play_audio.cpp
+++ b/tools/play_audio/play_audio.cpp
@@ -17,7 +17,7 @@
 #include "client_socket.h"
 #include "sdl_wrapper.h"
 
-#include "glog/logging.h"
+#include "android-base/logging.h"
 #include "gflags/gflags.h"
 #include "opuscpp/opus_wrapper.h"
 #include <SDL2/SDL.h>
diff --git a/tools/play_audio/sdl_wrapper.cpp b/tools/play_audio/sdl_wrapper.cpp
index 11f76df..6989293 100644
--- a/tools/play_audio/sdl_wrapper.cpp
+++ b/tools/play_audio/sdl_wrapper.cpp
@@ -17,7 +17,7 @@
 
 #include "sdl_wrapper.h"
 
-#include "glog/logging.h"
+#include "android-base/logging.h"
 #include <SDL2/SDL.h>
 
 #include <cstdint>