*/
#ifndef _LOG_H_
#define _LOG_H_
-#include "config.h"
#include "LogMessageBuffer.h"
#include <iostream>
#include <fstream>
#include <pthread.h>
-#ifdef WITH_DLT
-#include <dlt/dlt.h>
-#endif
-
typedef enum {
LOG_DISABLED = 0,
LOG_ERROR = 1,
LOG_MAX_LEVEL
} LOG_MODES;
-#ifdef WITH_DLT
-typedef DltContext LogContext;
-#else
-typedef std::string LogContext;
-#endif
+/*The log context content is configuration dependend. Due
+ to the fact that we don't want to share the config file
+ in development headers, the real context is established
+ during the compiliation phase*/
+typedef void* LogContext;
class Log
{
static LOG_MODES consoleLogLevel;
static LOG_MODES dltLogLevel;
static Log* getInstance();
- void warning (LogContext *logContext, const std::string& moduleName, const std::basic_string<char>& output);
- void info (LogContext *logContext, const std::string& moduleName, const std::basic_string<char>& output);
- void error (LogContext *logContext, const std::string& moduleName, const std::basic_string<char>& output);
- void debug (LogContext *logContext, const std::string& moduleName, const std::basic_string<char>& output);
- void log(LogContext *logContext, LOG_MODES logMode, const std::string& moduleName, const std::basic_string<char>& output);
- LogContext* getLogContext();
+ void warning (LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output);
+ void info (LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output);
+ void error (LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output);
+ void debug (LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output);
+ void log(LogContext logContext, LOG_MODES logMode, const std::string& moduleName, const std::basic_string<char>& output);
+ LogContext getLogContext();
static void closeInstance();
private:
Log();
void LogToFile(std::string logMode, const std::string& moduleName, const std::basic_string<char>& output);
void LogToConsole(std::string logMode, const std::string& moduleName,const std::basic_string<char>& output);
-#ifdef WITH_DLT
- void LogToDltDaemon(LogContext *logContext, LOG_MODES logMode,const std::string& moduleName,const std::basic_string<char>& output);
-#endif
+ void LogToDltDaemon(LogContext logContext, LOG_MODES logMode,const std::string& moduleName,const std::basic_string<char>& output);
+
private:
std::ofstream* m_fileStream;
pthread_mutex_t m_LogBufferMutex;
#include "Log.h"
#include <iomanip>
+#include "config.h"
+#ifdef WITH_DLT
+#include <dlt/dlt.h>
+#endif
Log* Log::m_instance = NULL;
LOG_MODES Log::fileLogLevel = LOG_DISABLED;
LOG_MODES Log::consoleLogLevel = LOG_INFO;
+#ifdef WITH_DLT
LOG_MODES Log::dltLogLevel = LOG_DEBUG;
+#else
+LOG_MODES Log::dltLogLevel = LOG_DISABLED;
+#endif
Log::Log()
{
m_fileStream = new std::ofstream("/tmp/LayerManagerService.log");
pthread_mutex_init(&m_LogBufferMutex, NULL);
#ifdef WITH_DLT
+ m_logContext = new DltContext;
DLT_REGISTER_APP("LMSA","LayerManagerService");
- DLT_REGISTER_CONTEXT(m_logContext,"LMSC","LayerManagerService");
-#else
- m_logContext = "LMSC";
-#endif
+ DLT_REGISTER_CONTEXT(*((DltContext*)m_logContext),"LMSC","LayerManagerService");
+#else
+ m_logContext = NULL;
+#endif
+
+
}
Log* Log::getInstance()
pthread_mutex_destroy(&m_LogBufferMutex);
Log::m_instance = NULL;
#ifdef WITH_DLT
- DLT_UNREGISTER_CONTEXT(m_logContext);
+ DLT_UNREGISTER_CONTEXT(*((DltContext*)m_logContext));
+ delete ((DltContext*)m_logContext);
#endif
+ m_logContext = NULL;
}
-void Log::warning (LogContext* logContext, const std::string& moduleName, const std::basic_string<char>& output)
+void Log::warning (LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output)
{
log(logContext,LOG_WARNING, moduleName, output);
}
-void Log::info (LogContext* logContext,const std::string& moduleName, const std::basic_string<char>& output)
+void Log::info (LogContext logContext,const std::string& moduleName, const std::basic_string<char>& output)
{
log(logContext, LOG_INFO, moduleName, output);
}
-void Log::error (LogContext* logContext,const std::string& moduleName, const std::basic_string<char>& output)
+void Log::error (LogContext logContext,const std::string& moduleName, const std::basic_string<char>& output)
{
log(logContext, LOG_ERROR, moduleName, output);
}
-void Log::debug (LogContext* logContext, const std::string& moduleName, const std::basic_string<char>& output)
+void Log::debug (LogContext logContext, const std::string& moduleName, const std::basic_string<char>& output)
{
log(logContext, LOG_DEBUG, moduleName, output);
}
-void Log::log(LogContext* logContext, LOG_MODES logMode, const std::string& moduleName, const std::basic_string<char>& output)
+void Log::log(LogContext logContext, LOG_MODES logMode, const std::string& moduleName, const std::basic_string<char>& output)
{
std::string logString[LOG_MAX_LEVEL] = {"","ERROR","INFO","WARNING","DEBUG"};
std::string logOutLevelString = logString[LOG_INFO];
<< output << std::endl;
}
-LogContext* Log::getLogContext()
+LogContext Log::getLogContext()
{
- return &m_logContext;
+ return m_logContext;
}
#ifdef WITH_DLT
-void Log::LogToDltDaemon(LogContext *logContext, LOG_MODES logMode, const std::string& moduleName, const std::basic_string<char>& output)
+void Log::LogToDltDaemon(LogContext logContext, LOG_MODES logMode, const std::string& moduleName, const std::basic_string<char>& output)
{
std::stringstream oss;
dltString = oss.str();
switch ( logMode )
{
- case LOG_INFO : DLT_LOG(*logContext,DLT_LOG_INFO,DLT_STRING(dltString.c_str())); break;
- case LOG_ERROR : DLT_LOG(*logContext,DLT_LOG_ERROR,DLT_STRING(dltString.c_str())); break;
- case LOG_DEBUG : DLT_LOG(*logContext,DLT_LOG_DEBUG,DLT_STRING(dltString.c_str())); break;
- case LOG_WARNING : DLT_LOG(*logContext,DLT_LOG_WARN,DLT_STRING(dltString.c_str())); break;
+ case LOG_INFO : DLT_LOG(*((DltContext*)logContext),DLT_LOG_INFO,DLT_STRING(dltString.c_str())); break;
+ case LOG_ERROR : DLT_LOG(*((DltContext*)logContext),DLT_LOG_ERROR,DLT_STRING(dltString.c_str())); break;
+ case LOG_DEBUG : DLT_LOG(*((DltContext*)logContext),DLT_LOG_DEBUG,DLT_STRING(dltString.c_str())); break;
+ case LOG_WARNING : DLT_LOG(*((DltContext*)logContext),DLT_LOG_WARN,DLT_STRING(dltString.c_str())); break;
default:
- DLT_LOG(*logContext,DLT_LOG_INFO,DLT_STRING(dltString.c_str()));
+ DLT_LOG(*((DltContext*)logContext),DLT_LOG_INFO,DLT_STRING(dltString.c_str()));
}
}
#endif