Browse Source

added custom log output handler

dmuratshin 9 years ago
parent
commit
5af5803e5a
2 changed files with 24 additions and 6 deletions
  1. 20 6
      oxygine/src/core/log.cpp
  2. 4 0
      oxygine/src/core/log.h

+ 20 - 6
oxygine/src/core/log.cpp

@@ -7,6 +7,8 @@
 
 
 
+
+
 #if defined(ANDROID)
 #include <android/log.h>
 #define  LOG_TAG    "SDL"
@@ -22,7 +24,6 @@
 #endif
 
 
-
 namespace oxygine
 {
     bool _enabled = true;
@@ -51,23 +52,36 @@ namespace oxygine
             _enabled = false;
         }
 
+        void outDefault(const char* txt)
+        {
+            LOGD(txt);
+        }
+
+
         error_handler _eh = 0;
+        out_handler _oh = outDefault;
 
         void setErrorHandler(error_handler eh)
         {
             _eh = eh;
         }
 
+        void setOutHandler(out_handler h)
+        {
+            _oh = h;
+        }
+
+        out_handler getOutHandler()
+        {
+            return _oh;
+        }
+
         void out(const char* str)
         {
             if (!_enabled)
                 return;
 
-            //if (!fh)
-            //  fh = fopen("log.txt", "w");
-            //fprintf(fh, str);
-            //fflush(fh);
-            LOGD(str);
+            _oh(str);
         }
 
         void out_line(char* str, int i)

+ 4 - 0
oxygine/src/core/log.h

@@ -12,10 +12,14 @@ namespace oxygine
         void disable();
 
         typedef void (*error_handler)(const char* txt);
+        typedef void (*out_handler)(const char* txt);
 
         /*run your callback if log::error was called*/
         void setErrorHandler(error_handler);
 
+        void setOutHandler(out_handler);
+        out_handler getOutHandler();
+
         /**pure out to log*/
         void out(const char* str);