Commit 87b07372 authored by Robert Menzel's avatar Robert Menzel
Browse files

added logging for Android SDK in eclipse

parent b09e0f70
...@@ -41,6 +41,11 @@ ...@@ -41,6 +41,11 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#ifdef __ANDROID__
#include <android/log.h>
#endif
namespace ACGL{ namespace ACGL{
namespace Utils{ namespace Utils{
...@@ -57,7 +62,6 @@ public: ...@@ -57,7 +62,6 @@ public:
~CoutLikeStreamBuffer(); ~CoutLikeStreamBuffer();
void setPrefix( const std::string &_prefix ); void setPrefix( const std::string &_prefix );
private: private:
//virtual std::streamsize xsputn(const base_type::char_type* s, std::streamsize n) //virtual std::streamsize xsputn(const base_type::char_type* s, std::streamsize n)
...@@ -77,6 +81,12 @@ private: ...@@ -77,6 +81,12 @@ private:
size_t mBufferMaxSize; // size of the buffer size_t mBufferMaxSize; // size of the buffer
bool mNewLineIsAboutToStart; bool mNewLineIsAboutToStart;
#ifdef __ANDROID__
android_LogPriority mAndroidPriority;
public:
void setAndroidPriority( android_LogPriority _priority ) { mAndroidPriority = _priority; }
#endif
}; };
/* /*
...@@ -106,6 +116,15 @@ public: ...@@ -106,6 +116,15 @@ public:
mStreamBuffer->setPrefix( streamName.str() ); mStreamBuffer->setPrefix( streamName.str() );
} }
} }
#ifdef __ANDROID__
switch (DEBUG_LEVEL) {
case 0: mStreamBuffer->setAndroidPriority( ANDROID_LOG_DEBUG); break;
case 1: mStreamBuffer->setAndroidPriority( ANDROID_LOG_INFO); break;
case 2: mStreamBuffer->setAndroidPriority( ANDROID_LOG_WARN); break;
case 3: mStreamBuffer->setAndroidPriority( ANDROID_LOG_ERROR); break;
default: mStreamBuffer->setAndroidPriority( ANDROID_LOG_UNKNOWN);
}
#endif
unmute(); unmute();
} }
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
using namespace ACGL::Utils; using namespace ACGL::Utils;
CoutLikeStreamBuffer::CoutLikeStreamBuffer() : base_type() { CoutLikeStreamBuffer::CoutLikeStreamBuffer() : base_type() {
...@@ -35,12 +34,18 @@ CoutLikeStreamBuffer::base_type::int_type CoutLikeStreamBuffer::overflow(base_ty ...@@ -35,12 +34,18 @@ CoutLikeStreamBuffer::base_type::int_type CoutLikeStreamBuffer::overflow(base_ty
if ((mBufferSize >= mBufferMaxSize) || ( base_type::traits_type::eq_int_type(ch, base_type::traits_type::eof()))) { if ((mBufferSize >= mBufferMaxSize) || ( base_type::traits_type::eq_int_type(ch, base_type::traits_type::eof()))) {
if (mNewLineIsAboutToStart) { if (mNewLineIsAboutToStart) {
#ifndef __ANDROID__
std::cout << mPrefix; std::cout << mPrefix;
#endif
mNewLineIsAboutToStart = false; mNewLineIsAboutToStart = false;
} }
if (mBufferSize > 0) { if (mBufferSize > 0) {
mBuffer[mBufferSize] = (char) 0; mBuffer[mBufferSize] = (char) 0;
#ifdef __ANDROID__
__android_log_print( mAndroidPriority, mPrefix.c_str(), "%s", mBuffer );
#else
std::cout << mBuffer; std::cout << mBuffer;
#endif
mBufferSize = 0; mBufferSize = 0;
} }
} else { } else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment