2 * \file ocsd_msg_logger.cpp
5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "common/ocsd_msg_logger.h"
40 #define MSGLOG_OUT_MASK (ocsdMsgLogger::OUT_FILE | ocsdMsgLogger::OUT_STDERR | ocsdMsgLogger::OUT_STDOUT | ocsdMsgLogger::OUT_STR_CB)
42 ocsdMsgLogger::ocsdMsgLogger() :
43 m_outFlags(ocsdMsgLogger::OUT_STDOUT),
44 m_logFileName("ocsd_trace_decode.log"),
49 ocsdMsgLogger::~ocsdMsgLogger()
54 void ocsdMsgLogger::setLogOpts(int logOpts)
56 m_outFlags = logOpts & (MSGLOG_OUT_MASK);
59 void ocsdMsgLogger::setLogFileName(const char *fileName)
64 m_logFileName = fileName;
66 if(m_out_file.is_open())
69 if (m_logFileName.length())
70 m_outFlags |= (int)ocsdMsgLogger::OUT_FILE;
72 m_outFlags &= ~((int)ocsdMsgLogger::OUT_FILE);
75 void ocsdMsgLogger::setStrOutFn(ocsdMsgLogStrOutI *p_IstrOut)
77 m_pOutStrI = p_IstrOut;
79 m_outFlags |= (int)ocsdMsgLogger::OUT_STR_CB;
81 m_outFlags &= ~((int)ocsdMsgLogger::OUT_STR_CB);
84 void ocsdMsgLogger::LogMsg(const std::string &msg)
86 if(m_outFlags & OUT_STDOUT)
92 if(m_outFlags & OUT_STDERR)
98 if(m_outFlags & OUT_FILE)
100 if(!m_out_file.is_open())
102 m_out_file.open(m_logFileName.c_str(),std::fstream::out | std::fstream::app);
108 if (m_outFlags & OUT_STR_CB)
111 m_pOutStrI->printOutStr(msg);
115 const bool ocsdMsgLogger::isLogging() const
117 return (bool)((m_outFlags & MSGLOG_OUT_MASK) != 0);
120 /* End of File ocsd_msg_logger.cpp */