Commit 9f4e3b74 authored by w4t's avatar w4t

when using ofxImGuiLoggerChannel, optionally log to console as well

parent 02620f19
#include "ofxImGuiLoggerChannel.h" #include "ofxImGuiLoggerChannel.h"
//-------------------------------------------------------------- ofxImGui::LoggerChannel::LoggerChannel(){
consoleChannel = new ofConsoleLoggerChannel();
}
//--------------------------------------------------------------
ImGuiTextBuffer& ofxImGui::LoggerChannel::getBuffer(){ ImGuiTextBuffer& ofxImGui::LoggerChannel::getBuffer(){
static ImGuiTextBuffer sLogBuffer; // static log buffer for logger channel static ImGuiTextBuffer sLogBuffer; // static log buffer for logger channel
return sLogBuffer; return sLogBuffer;
...@@ -10,8 +13,10 @@ ImGuiTextBuffer& ofxImGui::LoggerChannel::getBuffer(){ ...@@ -10,8 +13,10 @@ ImGuiTextBuffer& ofxImGui::LoggerChannel::getBuffer(){
//-------------------------------------------------------------- //--------------------------------------------------------------
void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module, const std::string & message ){ void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module, const std::string & message ){
getBuffer().appendf( "[%s] %s: %s\n", ofGetLogLevelName( level, true ).c_str(), module.c_str(), message.c_str() ); getBuffer().appendf( "[%s] %s: %s\n", ofGetLogLevelName( level, true ).c_str(), module.c_str(), message.c_str() );
if(logToConsole) consoleChannel->log(level, module, message);
} }
//--------------------------------------------------------------
void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module, const char* format, ... ){ void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module, const char* format, ... ){
va_list args; va_list args;
va_start( args, format ); va_start( args, format );
...@@ -19,9 +24,11 @@ void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module, ...@@ -19,9 +24,11 @@ void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module,
va_end( args ); va_end( args );
} }
//--------------------------------------------------------------
void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module, const char* format, va_list args ){ void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module, const char* format, va_list args ){
getBuffer().appendf( "[%s] %s: ", ofGetLogLevelName( level, true ).c_str(), module.c_str() ); getBuffer().appendf( "[%s] %s: ", ofGetLogLevelName( level, true ).c_str(), module.c_str() );
getBuffer().appendfv( format, args ); getBuffer().appendfv( format, args );
if(logToConsole) consoleChannel->log(level, module, format, args);
} }
......
...@@ -9,14 +9,19 @@ namespace ofxImGui { ...@@ -9,14 +9,19 @@ namespace ofxImGui {
class LoggerChannel : public ofBaseLoggerChannel class LoggerChannel : public ofBaseLoggerChannel
{ {
public: public:
LoggerChannel();
static ImGuiTextBuffer & getBuffer(); static ImGuiTextBuffer & getBuffer();
void setLogToConsole(bool log){logToConsole = log;}
/// \brief Destroy the console logger channel. /// \brief Destroy the console logger channel.
virtual ~LoggerChannel(){}; virtual ~LoggerChannel(){};
void log( ofLogLevel level, const std::string & module, const std::string & message ); void log( ofLogLevel level, const std::string & module, const std::string & message );
void log( ofLogLevel level, const std::string & module, const char* format, ... ) OF_PRINTF_ATTR( 4, 5 ); void log( ofLogLevel level, const std::string & module, const char* format, ... ) OF_PRINTF_ATTR( 4, 5 );
void log( ofLogLevel level, const std::string & module, const char* format, va_list args ); void log( ofLogLevel level, const std::string & module, const char* format, va_list args );
bool logToConsole = true;
ofConsoleLoggerChannel * consoleChannel = nullptr;
}; };
} // end namespace ofxImGui } // end namespace ofxImGui
......
Markdown is supported
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