Add output mode and flags to standard library message logger to allow attachment of external print string interface. This allows client programs to use built in logger, but supply string printing as part of the app. (e.g. perf may use this to in --dump command).
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/include/common/ocsd_msg_logger.h | 18 ++++++++++++++++-- decoder/source/ocsd_msg_logger.cpp | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/decoder/include/common/ocsd_msg_logger.h b/decoder/include/common/ocsd_msg_logger.h index ad73301..c40af91 100644 --- a/decoder/include/common/ocsd_msg_logger.h +++ b/decoder/include/common/ocsd_msg_logger.h @@ -38,6 +38,15 @@ #include <string> #include <fstream>
+class ocsdMsgLogStrOutI +{ +public: + ocsdMsgLogStrOutI() {}; + virtual ~ocsdMsgLogStrOutI() {}; + + virtual void printOutStr(const std::string &outStr) = 0; +}; + class ocsdMsgLogger { public: @@ -48,11 +57,15 @@ public: OUT_NONE = 0, OUT_FILE = 1, OUT_STDERR = 2, - OUT_STDOUT = 4 + OUT_STDOUT = 4, + OUT_STR_CB = 8 /* output to external string callback interface */ } output_dest;
void setLogOpts(int logOpts); - void setLogFileName(const char *fileName); + const int getLogOpts() const { return m_outFlags; }; + + void setLogFileName(const char *fileName); + void setStrOutFn(ocsdMsgLogStrOutI *p_IstrOut);
void LogMsg(const std::string &msg);
@@ -63,6 +76,7 @@ private:
std::string m_logFileName; std::fstream m_out_file; + ocsdMsgLogStrOutI *m_pOutStrI; };
#endif // ARM_OCSD_MSG_LOGGER_H_INCLUDED diff --git a/decoder/source/ocsd_msg_logger.cpp b/decoder/source/ocsd_msg_logger.cpp index 02b3921..2ddf4ee 100644 --- a/decoder/source/ocsd_msg_logger.cpp +++ b/decoder/source/ocsd_msg_logger.cpp @@ -37,9 +37,12 @@ #include <iostream> #include <sstream>
+#define MSGLOG_OUT_MASK (ocsdMsgLogger::OUT_FILE | ocsdMsgLogger::OUT_STDERR | ocsdMsgLogger::OUT_STDOUT | ocsdMsgLogger::OUT_STR_CB) + ocsdMsgLogger::ocsdMsgLogger() : m_outFlags(ocsdMsgLogger::OUT_STDOUT), - m_logFileName("ocsd_trace_decode.log") + m_logFileName("ocsd_trace_decode.log"), + m_pOutStrI(0) { }
@@ -50,7 +53,7 @@ ocsdMsgLogger::~ocsdMsgLogger()
void ocsdMsgLogger::setLogOpts(int logOpts) { - m_outFlags = logOpts & (ocsdMsgLogger::OUT_FILE | ocsdMsgLogger::OUT_STDERR | ocsdMsgLogger::OUT_STDOUT); + m_outFlags = logOpts & (MSGLOG_OUT_MASK); }
void ocsdMsgLogger::setLogFileName(const char *fileName) @@ -60,6 +63,10 @@ void ocsdMsgLogger::setLogFileName(const char *fileName) m_out_file.close(); }
+void ocsdMsgLogger::setStrOutFn(ocsdMsgLogStrOutI *p_IstrOut) +{ + m_pOutStrI = p_IstrOut; +}
void ocsdMsgLogger::LogMsg(const std::string &msg) { @@ -84,11 +91,17 @@ void ocsdMsgLogger::LogMsg(const std::string &msg) m_out_file << msg; m_out_file.flush(); } + + if (m_outFlags & OUT_STR_CB) + { + if (m_pOutStrI) + m_pOutStrI->printOutStr(msg); + } }
const bool ocsdMsgLogger::isLogging() const { - return (bool)((m_outFlags & (ocsdMsgLogger::OUT_FILE | ocsdMsgLogger::OUT_STDERR | ocsdMsgLogger::OUT_STDOUT)) != 0); + return (bool)((m_outFlags & MSGLOG_OUT_MASK) != 0); }
/* End of File ocsd_msg_logger.cpp */