Browse Source

android: Send nout to Android log, don't duplicate output to stderr

rdb 4 years ago
parent
commit
396e623aba
3 changed files with 13 additions and 4 deletions
  1. 1 1
      dtool/src/prc/androidLogStream.cxx
  2. 2 2
      dtool/src/prc/androidLogStream.h
  3. 10 1
      dtool/src/prc/notify.cxx

+ 1 - 1
dtool/src/prc/androidLogStream.cxx

@@ -92,7 +92,7 @@ overflow(int ch) {
  */
 void AndroidLogStream::AndroidLogStreamBuf::
 write_char(char c) {
-  nout.put(c);
+  //nout.put(c);
   if (c == '\n') {
     // Write a line to the log file.
     __android_log_write(_priority, _tag.c_str(), _data.c_str());

+ 2 - 2
dtool/src/prc/androidLogStream.h

@@ -44,10 +44,10 @@ private:
     std::string _data;
   };
 
-  AndroidLogStream(int priority);
-
 public:
+  AndroidLogStream(int priority);
   virtual ~AndroidLogStream();
+
   static std::ostream &out(NotifySeverity severity);
 };
 

+ 10 - 1
dtool/src/prc/notify.cxx

@@ -31,6 +31,8 @@
 
 #ifdef ANDROID
 #include <android/log.h>
+
+#include "androidLogStream.h"
 #endif
 
 using std::cerr;
@@ -345,8 +347,9 @@ assert_failure(const char *expression, int line,
 
 #ifdef ANDROID
   __android_log_assert("assert", "Panda3D", "Assertion failed: %s", message.c_str());
-#endif
+#else
   nout << "Assertion failed: " << message << "\n";
+#endif
 
   // This is redefined here, shadowing the defining in config_prc.h, so we can
   // guarantee it has already been constructed.
@@ -477,6 +480,12 @@ config_initialized() {
         }
 #endif  // BUILD_IPHONE
       }
+#ifdef ANDROID
+    } else {
+      // By default, we always redirect the notify stream to the Android log.
+      Notify *ptr = Notify::ptr();
+      ptr->set_ostream_ptr(new AndroidLogStream(ANDROID_LOG_INFO), true);
+#endif
     }
   }
 }