Use the event loop name instead of thread name for AOS_LOG

This kills 2 birds with 1 stone.
  1) A simulated event loop should print out the name of each event
     loop, not the program name.
  2) prctl(PR_GET_NAME, thread_name_array) can require higher privileges
     sometimes, and is un-necesary for simulations.  See 1)

Change-Id: I48731b1cabe34ec66a97f27ee720ba3081da4e94
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/logging/implementations.h b/aos/logging/implementations.h
index de1a8dd..36a4411 100644
--- a/aos/logging/implementations.h
+++ b/aos/logging/implementations.h
@@ -13,6 +13,7 @@
 #include <functional>
 #include <memory>
 #include <string>
+#include <string_view>
 
 #include "aos/logging/context.h"
 #include "aos/logging/interface.h"
@@ -92,6 +93,12 @@
  public:
   StreamLogImplementation(FILE *stream);
 
+  // Returns the name of this actual thread as the name.
+  std::string_view MyName() override {
+    internal::Context *context = internal::Context::Get();
+    return context->MyName();
+  }
+
  private:
   void HandleMessage(const LogMessage &message) override;
 
@@ -108,13 +115,18 @@
 class CallbackLogImplementation : public HandleMessageLogImplementation {
  public:
   CallbackLogImplementation(
-      const ::std::function<void(const LogMessage &)> &callback)
-      : callback_(callback) {}
+      const ::std::function<void(const LogMessage &)> &callback,
+      const std::string *name)
+      : callback_(callback), name_(name) {}
+
+  // Returns the provided name.  This is most likely the event loop name.
+  std::string_view MyName() override { return *name_; }
 
  private:
   void HandleMessage(const LogMessage &message) override { callback_(message); }
 
   ::std::function<void(const LogMessage &)> callback_;
+  const std::string *name_;
 };
 
 class ScopedLogRestorer {
@@ -136,18 +148,18 @@
 
 // Fills in *message according to the given inputs (with type kString).
 // Used for implementing LogImplementation::DoLog.
-void FillInMessage(log_level level,
+void FillInMessage(log_level level, std::string_view name,
                    ::aos::monotonic_clock::time_point monotonic_now,
                    const char *format, va_list ap, LogMessage *message)
-    __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)));
+    __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 4, 0)));
 
-__attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 4, 5))) static inline void
-FillInMessageVarargs(log_level level,
+__attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 5, 6))) static inline void
+FillInMessageVarargs(log_level level, std::string_view name,
                      ::aos::monotonic_clock::time_point monotonic_now,
                      LogMessage *message, const char *format, ...) {
   va_list ap;
   va_start(ap, format);
-  FillInMessage(level, monotonic_now, format, ap, message);
+  FillInMessage(level, name, monotonic_now, format, ap, message);
   va_end(ap);
 }