Make logger work again with an external SimulatedEventLoopFactory

The only way to get a node, and therefore a remapped_configuration_ and
therefore be able to call Register(SimulatedEventLoopFactory *factory)
is to be able to get the remapped config at all times.  This makes that
work again.

Change-Id: I1be0e751f4b92d3712f73fdff2b5edee4d453a40
diff --git a/aos/events/logging/logger.cc b/aos/events/logging/logger.cc
index 23dc802..d5626a9 100644
--- a/aos/events/logging/logger.cc
+++ b/aos/events/logging/logger.cc
@@ -224,6 +224,7 @@
     : sorted_message_reader_(filename),
       replay_configuration_(replay_configuration) {
   channels_.resize(logged_configuration()->channels()->size());
+  MakeRemappedConfig();
 }
 
 LogReader::~LogReader() {
@@ -235,9 +236,6 @@
 }
 
 const Configuration *LogReader::configuration() const {
-  CHECK(remapped_configuration_ != nullptr)
-      << ": Need to call Register() before the remapped config will be "
-         "generated.";
   return remapped_configuration_;
 }
 
@@ -263,7 +261,6 @@
 }
 
 void LogReader::Register() {
-  MakeRemappedConfig();
   event_loop_factory_unique_ptr_ =
       std::make_unique<SimulatedEventLoopFactory>(configuration(), node());
   Register(event_loop_factory_unique_ptr_.get());
@@ -300,10 +297,18 @@
               << configuration::CleanedChannelToString(original_channel);
       channel_name = remapped_channels_[i];
     }
+
     VLOG(1) << "Going to remap channel " << channel_name << " " << channel_type;
-    channels_[i] = event_loop_->MakeRawSender(CHECK_NOTNULL(
-        configuration::GetChannel(event_loop_->configuration(), channel_name,
-                                  channel_type, "", nullptr)));
+    const Channel *channel = configuration::GetChannel(
+        event_loop_->configuration(), channel_name, channel_type,
+        event_loop_->name(), event_loop_->node());
+
+    CHECK(channel != nullptr)
+        << ": Unable to send {\"name\": \"" << channel_name
+        << "\", \"type\": \"" << channel_type
+        << "\"} because it is not in the provided configuration.";
+
+    channels_[i] = event_loop_->MakeRawSender(channel);
   }
 
   timer_handler_ = event_loop_->AddTimer([this]() {
@@ -392,8 +397,6 @@
 
 void LogReader::RemapLoggedChannel(std::string_view name, std::string_view type,
                                    std::string_view add_prefix) {
-  CHECK(remapped_configuration_ == nullptr)
-      << "Must call RemapLoggedChannel before calling Register().";
   for (size_t ii = 0; ii < logged_configuration()->channels()->size(); ++ii) {
     const Channel *const channel = logged_configuration()->channels()->Get(ii);
     if (channel->name()->str() == name &&
@@ -405,6 +408,7 @@
       VLOG(1) << "Remapping channel "
               << configuration::CleanedChannelToString(channel)
               << " to have name " << remapped_channels_[ii];
+      MakeRemappedConfig();
       return;
     }
   }