From e30847e6d7e32acacbf887fdb39c3334a4b1638d Mon Sep 17 00:00:00 2001
From: Nicolas Jager <nicolas.jager@savoirfairelinux.com>
Date: Fri, 14 Oct 2016 14:05:24 -0400
Subject: [PATCH] internal : save debug output to file

Change-Id: Id637ece76a98ad4ad8a45944b1c356cc57f263c9
Tuleap: #1224
---
 RingDebug.cpp | 21 +++++++++++++++++++--
 RingDebug.h   |  6 +++++-
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/RingDebug.cpp b/RingDebug.cpp
index be2860b..c5475b2 100644
--- a/RingDebug.cpp
+++ b/RingDebug.cpp
@@ -24,6 +24,7 @@ using namespace RingClientUWP;
 
 using namespace Platform;
 using namespace Windows::UI::Core;
+using namespace Windows::Storage;
 
 void
 RingDebug::print(const std::string& message,
@@ -53,5 +54,21 @@ RingDebug::print(const std::string& message,
     OutputDebugString((wString + L"\n").c_str());
 
     /* fire the event. */
-    messageToScreen(ref new String(wString.c_str(), wString.length()));
-}
\ No newline at end of file
+    auto line = ref new String(wString.c_str(), wString.length());
+    messageToScreen(line);
+    FileIO::AppendTextAsync(_logFile, line+"\n");
+}
+
+RingClientUWP::RingDebug::RingDebug()
+{
+    StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder;
+
+    StorageFile^ logFile;
+
+    task<StorageFile^>(storageFolder->CreateFileAsync("debug.log", CreationCollisionOption::ReplaceExisting)).then([this](StorageFile^ file)
+    {
+        this->_logFile = file;
+    });
+
+}
+
diff --git a/RingDebug.h b/RingDebug.h
index c7cee0a..61e0c2d 100644
--- a/RingDebug.h
+++ b/RingDebug.h
@@ -17,6 +17,8 @@
 **************************************************************************/
 #pragma once
 
+using namespace Windows::Storage;
+
 namespace RingClientUWP
 {
 
@@ -40,6 +42,8 @@ public:
         }
     }
 
+    property StorageFile^ _logFile;
+
     /* properties */
 
     /* functions */
@@ -51,7 +55,7 @@ internal:
     event debugMessageToScreen^ messageToScreen;
 
 private:
-    RingDebug() {}; // singleton
+    RingDebug(); // singleton
 };
 
 void WriteLine(String^ str)
-- 
GitLab