diff options
Diffstat (limited to 'src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger')
5 files changed, 760 insertions, 0 deletions
diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/LTKLogger.cpp b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/LTKLogger.cpp new file mode 100644 index 00000000..75ad218e --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/LTKLogger.cpp @@ -0,0 +1,399 @@ +/***************************************************************************************** +* Copyright (c) 2007 Hewlett-Packard Development Company, L.P. +* Permission is hereby granted, free of charge, to any person obtaining a copy of +* this software and associated documentation files (the "Software"), to deal in +* the Software without restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +* Software, and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*****************************************************************************************/ + +/************************************************************************ + * SVN MACROS + * + * $LastChangedDate: 2008-01-10 14:36:54 +0530 (Thu, 10 Jan 2008) $ + * $Revision: 353 $ + * $Author: charakan $ + * + ************************************************************************/ +/************************************************************************ + * FILE DESCR: Implementation of the Debug Logging Module + * + * CONTENTS: + * + * AUTHOR: Balaji R. + * + * DATE: December 23, 2004 + * CHANGE HISTORY: + * Author Date Description of change + ************************************************************************/ + +#include "LTKLogger.h" +#include "LTKMacros.h" +#include "LTKErrorsList.h" +#include "LTKOSUtil.h" +#include "LTKOSUtilFactory.h" + +LTKLoggerInterface* LTKLogger::loggerInstance = NULL; + +/********************************************************************************** +* AUTHOR : Balaji R. +* DATE : 23-DEC-2004 +* NAME : LTKLogger +* DESCRIPTION : Default Constructor +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +LTKLogger::LTKLogger(): +m_debugLevel(LTKLogger::LTK_LOGLEVEL_ERR), +m_logFileName(DEFAULT_LOG_FILE), +m_logStatus(INACTIVE), +m_isTimeStamped(true) +{ +} + +/********************************************************************************** +* AUTHOR : Balaji R. +* DATE : 23-DEC-2004 +* NAME : LTKLogger +* DESCRIPTION : destructor +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +LTKLogger::~LTKLogger() +{ + stopLog(); +} + +/********************************************************************************** +* AUTHOR : Balaji R. +* DATE : 23-DEC-2004 +* NAME : operator() +* DESCRIPTION : overloaded function call operator +* ARGUMENTS : msgDebugLevel - log level of the messages to be logged +* RETURNS : reference to an output stream object +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +ostream& LTKLogger::operator()(const EDebugLevel& msgDebugLevel, + const string& fileName, + int lineNumber) +{ + if ( m_debugLevel <= msgDebugLevel ) + { + writeAuxInfo(fileName, lineNumber); + + switch ( msgDebugLevel ) + { + + case LTKLogger::LTK_LOGLEVEL_ALL: + m_logFile << "[All] "; + break; + + case LTKLogger::LTK_LOGLEVEL_VERBOSE: + m_logFile << "[Verbose] "; + break; + case LTKLogger::LTK_LOGLEVEL_DEBUG: + m_logFile << "[Debug] "; + break; + + case LTKLogger::LTK_LOGLEVEL_INFO: + m_logFile << "[Info] "; + break; + + case LTKLogger::LTK_LOGLEVEL_ERR: + m_logFile << "[Error] "; + break; + } + + m_logFile.flush(); + + return m_logFile; + } + + // if m_debugLevel is higher than the message importance, + // then don't attempt to process it's input + return m_ofstream; +} + +/********************************************************************************** +* AUTHOR : Balaji R. +* DATE : 23-DEC-2004 +* NAME : writeAuxInfo +* DESCRIPTION : writes the data, time, file, line no. information into the log file +* ARGUMENTS : fileName - name of file containing the log message +* lineNumber - line number of the log message +* RETURNS : SUCCESS on successful writing of the auxiliary information +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +int LTKLogger::writeAuxInfo(const string& fileName, int lineNumber) +{ + + #ifdef LOGGEROFF + return FAILURE; + #endif + + if(m_isTimeStamped) + { + LTKOSUtil *pOSUtil = LTKOSUtilFactory::getInstance() ; + + string formattedTimeStr ; + pOSUtil->getSystemTimeString(formattedTimeStr) ; + m_logFile << formattedTimeStr << ' '; + delete pOSUtil ; + + /* + time_t rawtime; + + time(&rawtime); + + string timeStr = ctime(&rawtime); + + string formattedTimeStr = timeStr.substr(0, 24); + + m_logFile << formattedTimeStr << ' '; + */ + } + + m_logFile << fileName.substr(fileName.find_last_of(SEPARATOR) + 1, fileName.size()); + + if(lineNumber != 0) + { + m_logFile << '(' << lineNumber << "): "; + } + + return SUCCESS; +} + + +/*************************************************************************** +* AUTHOR : Balaji R. +* DATE : 23-DEC-2004 +* NAME : setLogLevel +* DESCRIPTION : sets the level of the messages to be logged +* ARGUMENTS : debugLevel - level of the messages to be logged +* RETURNS : SUCCESS on successful set operation +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +****************************************************************************/ + +int LTKLogger::setLogLevel(const EDebugLevel& debugLevel) +{ + #ifdef LOGGEROFF + return FAILURE; + #endif + + m_debugLevel = debugLevel; + + return SUCCESS; +} + +/**************************************************************************** +* AUTHOR : Balaji R. +* DATE : 23-DEC-2004 +* NAME : setLogFileName +* DESCRIPTION : sets the name of the file to be used for logging +* ARGUMENTS : logFileName - name of the file to be used for logging +* RETURNS : Nothing +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +* Balaji MNA 07-Apr-2009 To fix bug: LIPTKT-600 +*****************************************************************************/ + +void LTKLogger::setLogFileName(const string& logFileName) +{ + + #ifdef LOGGEROFF + return; + #endif + + m_logStatus = INACTIVE; + m_logFileName = logFileName; +} + +/********************************************************************************** +* AUTHOR : Balaji R. +* DATE : 23-DEC-2004 +* NAME : getLogLevel +* DESCRIPTION : returns the log of messages to be logged +* ARGUMENTS : +* RETURNS : log of messages to be logged +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +LTKLogger::EDebugLevel LTKLogger::getLogLevel() +{ + #ifdef LOGGEROFF + return string("Logger is off"); + #endif + return m_debugLevel; +} + +/***************************************************************************** +* AUTHOR : Balaji R. +* DATE : 23-DEC-2004 +* NAME : getLogFileName +* DESCRIPTION : returns the name of the log file +* ARGUMENTS : +* RETURNS : name of the log file +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +******************************************************************************/ + +const string& LTKLogger::getLogFileName() +{ + return m_logFileName; +} + +/**************************************************************************** +* AUTHOR : Balaji R. +* DATE : 23-DEC-2004 +* NAME : startLog +* DESCRIPTION : starts the logging operation +* ARGUMENTS : +* RETURNS : SUCCESS on successful start of logging +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +****************************************************************************/ + +int LTKLogger::startLog(bool isTimeStamped) +{ + + if (m_debugLevel == LTK_LOGLEVEL_OFF ) + return FAILURE; + + if(m_logStatus == INACTIVE) + { + m_isTimeStamped = isTimeStamped; + + if(m_logFileName != "") + { + m_logFile.close(); + + m_logFile.clear(); + + m_logFile.open(m_logFileName.c_str(), ios::app); + } + + if(m_logFileName == "" || !m_logFile) + { + // log the non-existance of m_logFileName file path is unable to open m_logFileName + + return (ELOG_FILE_NOT_EXIST); + + m_logFile.close(); + + m_logFile.clear(); + + m_logFile.open(m_logFileName.c_str(), ios::app); + } + + m_logStatus = ACTIVE; + } + + return SUCCESS; +} + +/**************************************************************************** +* AUTHOR : Nidhi sharma +* DATE : 12-SEPT-2005 +* NAME : getInstance +* DESCRIPTION : This file will return the address of the Logger instance. +* ARGUMENTS : +* RETURNS : Address of the Logger instance. +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +* Thanigai 28-NOV-05 returning the address of global Logger object +* is giving runtime error, because the vfptr is not +* getting initialized(vtable). So implementing the +* workaround by allocating a new Logger object runtime. +*****************************************************************************/ + +LTKLoggerInterface* LTKLogger::getInstance() +{ + if(loggerInstance == NULL) + { + loggerInstance = new LTKLogger(); + } + + return loggerInstance; + +} + +/**************************************************************************** +* AUTHOR : Nidhi sharma +* DATE : 12-SEPT-2005 +* NAME : destroyLoggerInstance +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*****************************************************************************/ +void LTKLogger::destroyLoggerInstance() +{ + if (loggerInstance != NULL) + { + delete loggerInstance; + loggerInstance = NULL; + } +} + +/**************************************************************************** +* AUTHOR : Thanigai +* DATE : 12-SEPT-2005 +* NAME : stopLog +* DESCRIPTION : stops the logging operation +* ARGUMENTS : +* RETURNS : SUCCESS on successful stop of logging +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*****************************************************************************/ + +int LTKLogger::stopLog() +{ + if (m_debugLevel == LTK_LOGLEVEL_OFF ) + return FAILURE; + + if(m_logFileName != "") + { + m_logFile.close(); + m_logStatus = INACTIVE; + return 0; + } + return FAILURE; +} + diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.cpp b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.cpp new file mode 100644 index 00000000..2fa735bb --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.cpp @@ -0,0 +1,240 @@ +/****************************************************************************** +* Copyright (c) 2006 Hewlett-Packard Development Company, L.P. +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE +********************************************************************************/ + +/****************************************************************************** + * SVN MACROS + * + * $LastChangedDate$ + * $Revision$ + * $Author$ + * + ************************************************************************/ +/*************************************************************************** + * FILE DESCR: DLL Implementation file for logger module + * + * CONTENTS: + * DllMain + * + * + * AUTHOR: Nidhi Sharma + * + * DATE: April 01, 2008 + * + * CHANGE HISTORY: + * + * Author Date Description of change + ************************************************************************/ +#include "logger.h" +#include "LTKLoggerUtil.h" +#include "LTKLoggerInterface.h" +#include "LTKLogger.h" +#include "LTKMacros.h" +#include "LTKErrorsList.h" + + + +LTKLoggerInterface* ptrLog = LTKLogger::getInstance(); + +/************************************************************************ +* AUTHOR : Nidhi Sharma +* DATE : 01-APR-2008 +* NAME : DllMain +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +************************************************************************/ +#ifdef _WIN32 +BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, + LPVOID lpReserved) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + break; + case DLL_THREAD_ATTACH: + break; + + case DLL_THREAD_DETACH: + break; + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} +#endif // #ifdef _WIN32 + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 01-APR-2008 +* NAME : getLoggerInstance +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +***************************************************************************/ +LTKLoggerInterface* getLoggerInstance() +{ + return ptrLog; +} + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 01-APR-2008 +* NAME : destroyLogger +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +***************************************************************************/ +void destroyLogger() +{ + ptrLog = NULL; + LTKLogger::destroyLoggerInstance(); +} + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 01-APR-2008 +* NAME : setLogFileName +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +***************************************************************************/ +void setLoggerFileName(const string& logFileName) +{ + if (!ptrLog) return; + ptrLog->setLogFileName(logFileName); +} + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 01-APR-2008 +* NAME : setLogLevel +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +***************************************************************************/ +int setLoggerLevel(LTKLogger::EDebugLevel logLevel) +{ + if (!ptrLog) return FAILURE; + return ptrLog->setLogLevel(logLevel); +} + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 01-APR-2008 +* NAME : getLogFileName +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +***************************************************************************/ +const string& getLoggerFileName() +{ + static string emptyStr; + if (!ptrLog) return emptyStr; + return ptrLog->getLogFileName(); +} + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 03-APR-2008 +* NAME : getLogLevel +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +***************************************************************************/ +LTKLogger::EDebugLevel getLoggerLevel() +{ + if (!ptrLog) return LTKLogger::LTK_LOGLEVEL_OFF; + return ptrLog->getLogLevel(); +} + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 02-APR-2008 +* NAME : startLog +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +***************************************************************************/ +void startLogger() +{ + if (!ptrLog) return; + ptrLog->startLog(); +} + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 02-APR-2008 +* NAME : startLog +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +***************************************************************************/ +void stopLogger() +{ + if (!ptrLog) return; + ptrLog->stopLog(); +} + + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 08-APR-2008 +* NAME : logMessage +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +***************************************************************************/ +ostream& logMessage(LTKLogger::EDebugLevel logLevel, const string& fileName, + int lineNumber) +{ + if (!ptrLog) return LTKLoggerUtil::m_emptyStream; + return (*ptrLog)(logLevel, fileName, lineNumber); +}
\ No newline at end of file diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.def b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.def new file mode 100644 index 00000000..5a47ec22 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.def @@ -0,0 +1,10 @@ +EXPORTS + getLoggerInstance @1 + setLoggerFileName @2 + setLoggerLevel @3 + getLoggerFileName @4 + getLoggerLevel @5 + startLogger @6 + stopLogger @7 + logMessage @9 + destroyLogger @10
\ No newline at end of file diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.h b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.h new file mode 100644 index 00000000..dfcbde30 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.h @@ -0,0 +1,92 @@ +/***************************************************************************************** +* Copyright (c) 2006 Hewlett-Packard Development Company, L.P. +* Permission is hereby granted, free of charge, to any person obtaining a copy of +* this software and associated documentation files (the "Software"), to deal in +* the Software without restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +* Software, and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*****************************************************************************************/ + +/************************************************************************ + * SVN MACROS + * + * $LastChangedDate$ + * $Revision$ + * $Author$ + * + ************************************************************************/ + +/************************************************************************ + * FILE DESCR: Definitions for Logger dll exporting functions. + * + * CONTENTS: + * + * AUTHOR: Nidhi Sharma + * + * DATE: 01-April-2008 + * + * CHANGE HISTORY: + * + * Author Date Description + ************************************************************************/ +#ifndef __LOGGERDLL_H__ +#define __LOGGERDLL_H__ + +#ifndef _WIN32 +#include <dlfcn.h> +#else +#include <windows.h> +#endif + + +#ifdef _WIN32 +#ifdef LOGGER_EXPORTS +#define LOGGER_API __declspec(dllexport) +#else +#define LOGGER_API __declspec(dllimport) +#endif //#ifdef LOGGER_EXPORTS +#else +#define LOGGER_API +#endif //#ifdef _WIN32 + +class LTKLoggerInterface; +#include "LTKLogger.h" +#include "LTKTypes.h" + + +extern "C" LOGGER_API LTKLoggerInterface* getLoggerInstance(); + +extern "C" LOGGER_API void destroyLogger(); + +extern "C" LOGGER_API void setLoggerFileName(const string& logFileName); + +extern "C" LOGGER_API int setLoggerLevel(LTKLogger::EDebugLevel logLevel); + +extern "C" LOGGER_API const string& getLoggerFileName(); + +extern "C" LOGGER_API LTKLogger::EDebugLevel getLoggerLevel(); + +extern "C" LOGGER_API void startLogger(); + +extern "C" LOGGER_API void stopLogger(); + +extern "C" LOGGER_API ostream& logMessage(LTKLogger::EDebugLevel, + const string& fileName, + int lineNumber); + + + + +#endif //#ifndef __LOGGERDLL_H__ diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.pro b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.pro new file mode 100644 index 00000000..5f1cc5ac --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/util/logger/logger.pro @@ -0,0 +1,19 @@ +LIPILIBS = ltkutil +include(../../lipiplugin.pri) +CONFIG -= exceptions + +HEADERS += \ + logger.h \ + +SOURCES += \ + logger.cpp \ + LTKLogger.cpp \ + +INCLUDEPATH += \ + ../lib \ + +win32 { + DEFINES += LOGGER_EXPORTS + LIBS += Advapi32.lib + #DEF_FILE = logger.def +} |