From d4228e21db29a1e9efa9f88a76055946bb3e6e5b Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@cnes.fr>
Date: Tue, 6 Mar 2018 14:58:31 +0100
Subject: [PATCH] ENH: Make std::cout the default output for library logs

---
 Modules/Core/Common/include/otbLogger.h |  3 +--
 Modules/Core/Common/src/otbLogger.cxx   | 10 ++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Modules/Core/Common/include/otbLogger.h b/Modules/Core/Common/include/otbLogger.h
index 7325a9adcd..5a70bff641 100644
--- a/Modules/Core/Common/include/otbLogger.h
+++ b/Modules/Core/Common/include/otbLogger.h
@@ -45,13 +45,12 @@ public:
   itkTypeMacro(Logger, itk::Logger);
 
   static Pointer Instance();
-
+  itkNewMacro(Self);
   
   // Overwrite this to provide custom formatting of log entries
   virtual std::string BuildFormattedEntry(itk::Logger::PriorityLevelType, std::string const&) ITK_OVERRIDE;
 
 protected:
-  itkNewMacro(Self);
   Logger();
   virtual ~Logger() ITK_OVERRIDE;
 
diff --git a/Modules/Core/Common/src/otbLogger.cxx b/Modules/Core/Common/src/otbLogger.cxx
index 98b099ac57..0ed6b6f790 100644
--- a/Modules/Core/Common/src/otbLogger.cxx
+++ b/Modules/Core/Common/src/otbLogger.cxx
@@ -21,6 +21,8 @@
 #include "otbLogger.h"
 #include "itksys/SystemTools.hxx"
 #include "otbConfigurationManager.h"
+#include "itkStdStreamLogOutput.h"
+#include <iostream>
 
 namespace otb
 {
@@ -30,8 +32,16 @@ Logger::Pointer Logger::Singleton = ITK_NULLPTR;
 Logger::Pointer Logger::Instance()
 {
   if(!Logger::Singleton)
+    {
     Logger::Singleton = Logger::New();
 
+    // By default, redirect logs to std::cout
+    itk::StdStreamLogOutput::Pointer defaultOutput = itk::StdStreamLogOutput::New();
+    defaultOutput->SetStream(std::cout);
+
+    Logger::Singleton->AddLogOutput(defaultOutput);
+    }
+  
   return Logger::Singleton;
 }
 
-- 
GitLab