summaryrefslogtreecommitdiff
path: root/AudioManagerUtilities/src
diff options
context:
space:
mode:
Diffstat (limited to 'AudioManagerUtilities/src')
-rw-r--r--AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp2
-rw-r--r--AudioManagerUtilities/src/CAmDbusWrapper.cpp2
-rw-r--r--AudioManagerUtilities/src/CAmDltWrapper.cpp750
-rwxr-xr-xAudioManagerUtilities/src/CAmLogWrapper.cpp125
-rwxr-xr-xAudioManagerUtilities/src/CAmLoggerDlt.cpp223
-rwxr-xr-xAudioManagerUtilities/src/CAmLoggerFile.cpp252
-rwxr-xr-xAudioManagerUtilities/src/CAmLoggerStdOut.cpp264
-rw-r--r--AudioManagerUtilities/src/CAmSocketHandler.cpp2
-rw-r--r--AudioManagerUtilities/src/CAmWatchdog.cpp2
9 files changed, 924 insertions, 698 deletions
diff --git a/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp b/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp
index e22dcd6..d110293 100644
--- a/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp
+++ b/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp
@@ -27,7 +27,7 @@
#include <vector>
#include "audiomanagertypes.h"
#include "CAmSocketHandler.h"
-#include "CAmDltWrapper.h"
+#include "CAmLogWrapper.h"
#include "CAmCommonAPIWrapper.h"
namespace am
diff --git a/AudioManagerUtilities/src/CAmDbusWrapper.cpp b/AudioManagerUtilities/src/CAmDbusWrapper.cpp
index 504bf38..99a4eb2 100644
--- a/AudioManagerUtilities/src/CAmDbusWrapper.cpp
+++ b/AudioManagerUtilities/src/CAmDbusWrapper.cpp
@@ -29,7 +29,7 @@
#include <cassert>
#include <cstdlib>
#include <stdexcept>
-#include "CAmDltWrapper.h"
+#include "CAmLogWrapper.h"
#include "CAmSocketHandler.h"
namespace am
diff --git a/AudioManagerUtilities/src/CAmDltWrapper.cpp b/AudioManagerUtilities/src/CAmDltWrapper.cpp
index fff4a57..9a57242 100644
--- a/AudioManagerUtilities/src/CAmDltWrapper.cpp
+++ b/AudioManagerUtilities/src/CAmDltWrapper.cpp
@@ -22,134 +22,26 @@
*
*/
-#include <string>
-#include <iostream>
#include <string.h>
-#include <chrono>
-#include <ctime>
-#include <sys/types.h>
#include <unistd.h>
#include "CAmDltWrapper.h"
-namespace am
-{
-CAmDltWrapper *CAmDltWrapper::mpDLTWrapper = NULL;
-pthread_mutex_t CAmDltWrapper::mMutex = PTHREAD_MUTEX_INITIALIZER;
+using namespace std;
-const std::vector<const char *> CAmDltWrapper::mStr_error =
-{
- "E_OK",
- "E_UNKNOWN",
- "E_OUT_OF_RANGE",
- "E_NOT_USED",
- "E_DATABASE_ERROR",
- "E_ALREADY_EXISTS",
- "E_NO_CHANGE",
- "E_NOT_POSSIBLE",
- "E_NON_EXISTENT",
- "E_ABORTED",
- "E_WRONG_FORMAT",
- "E_COMMUNICATION",
- "E_MAX"
-};
-const std::vector<const char *> CAmDltWrapper::mStr_sourceState =
-{
- "SS_UNKNNOWN",
- "SS_ON",
- "SS_OFF",
- "SS_PAUSED",
- "SS_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_MuteState =
-{
- "MS_UNKNOWN",
- "MS_MUTED",
- "MS_UNMUTED",
- "MS_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_DomainState =
-{
- "DS_UNKNOWN",
- "DS_CONTROLLED",
- "DS_INDEPENDENT_STARTUP",
- "DS_INDEPENDENT_RUNDOWN",
- "DS_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_ConnectionState =
-{
- "CS_UNKNOWN",
- "CS_CONNECTING",
- "CS_CONNECTED",
- "CS_DISCONNECTING",
- "CS_DISCONNECTED",
- "CS_SUSPENDED",
- "CS_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_Availability =
-{
- "A_UNKNOWN",
- "A_AVAILABLE",
- "A_UNAVAILABLE",
- "A_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_Interrupt =
-{
- "IS_UNKNOWN",
- "IS_OFF",
- "IS_INTERRUPTED",
- "IS_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_Handle =
-{
- "H_UNKNOWN",
- "H_CONNECT",
- "H_DISCONNECT",
- "H_SETSOURCESTATE",
- "H_SETSINKVOLUME",
- "H_SETSOURCEVOLUME",
- "H_SETSINKSOUNDPROPERTY",
- "H_SETSOURCESOUNDPROPERTY",
- "H_SETSINKSOUNDPROPERTIES",
- "H_SETSOURCESOUNDPROPERTIES",
- "H_CROSSFADE",
- "H_SETVOLUMES",
- "H_SETSINKNOTIFICATION",
- "H_SETSOURCENOTIFICATION",
- "H_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_NotificationStatus =
+namespace am
{
- "NS_UNKNOWN",
- "NS_OFF",
- "NS_PERIODIC",
- "NS_MINIMUM",
- "NS_MAXIMUM",
- "NS_CHANGE",
- "NS_MAX"
-};
+CAmDltWrapper *CAmDltWrapper::mpDLTWrapper = NULL;
-std::string CAmDltWrapper::now()
-{
- std::time_t t(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
- struct tm *timeinfo(localtime(&t));
- char buffer[80];
- std::strftime(buffer, 80, "%D %T ", timeinfo);
- return (std::string(buffer));
-}
CAmDltWrapper *CAmDltWrapper::instanctiateOnce(const char *appid, const char *description, const bool debugEnabled, const logDestination logDest, const std::string Filename, bool onlyError)
{
if (!mpDLTWrapper)
{
- mpDLTWrapper = new CAmDltWrapper(appid, description, debugEnabled, logDest, Filename, onlyError);
+ IAmLogger *pLogger = CAmLogWrapper::instantiateOnce(appid, description
+ , (debugEnabled ? LS_ON : LS_OFF), static_cast<am_LogService_e>(logDest)
+ , Filename, onlyError);
+ mpDLTWrapper = new CAmDltWrapper(pLogger, debugEnabled, onlyError);
}
return (mpDLTWrapper);
@@ -162,8 +54,8 @@ CAmDltWrapper *CAmDltWrapper::instance()
// an application seems not to use our CAmDltWrapper class therefore create default
std::ostringstream description;
description << "PID=" << getpid() << " _=" << getenv("_");
- mpDLTWrapper = new CAmDltWrapper("AMDL", description.str().c_str());
- std::cerr << "Application doesn't call CAmDltWrapper::instanciateOnce!!!" << std::endl;
+ mpDLTWrapper = instanctiateOnce("AMDL", description.str().c_str());
+ std::cerr << "Application doesn't call CAmDltWrapper::instanctiateOnce!!!" << std::endl;
std::cerr << "-> CAmDltWrapper::instance registers DLT application [ AMDL | " << description.str() << " ]" << std::endl;
}
@@ -175,639 +67,109 @@ bool CAmDltWrapper::getEnabled()
return (mDebugEnabled);
}
-bool CAmDltWrapper::initNoDlt(DltLogLevelType loglevel, DltContext *context)
+CAmDltWrapper::CAmDltWrapper(IAmLogger *pLogger, bool debugEnabled, bool onlyError)
+ : mpLogger(pLogger)
+ , mpCurrentContext(NULL)
+ , mDebugEnabled(debugEnabled)
+ , mOnlyError(onlyError)
{
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- if (!context)
- {
- switch (loglevel)
- {
- case DLT_LOG_OFF:
- case DLT_LOG_FATAL:
- case DLT_LOG_ERROR:
- mNoDltContextData.buffer << "\033[0;31m" << "[DEF] [Erro] \033[0m";
- mLogOn = true;
- break;
- case DLT_LOG_WARN:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;33m" << "[DEF] [Warn] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- case DLT_LOG_INFO:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;36m" << "[DEF] [Info] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
- break;
- default:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;32m" << "[DEF] [Defa] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
- }
- }
- else
- {
- std::string con(mMapContext.at(context));
- switch (loglevel)
- {
- case DLT_LOG_OFF:
- case DLT_LOG_FATAL:
- case DLT_LOG_ERROR:
- mNoDltContextData.buffer << "\033[0;31m[" << con << "] [Erro] \033[0m";
- mLogOn = true;
- break;
- case DLT_LOG_WARN:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;33m[" << con << "] [Warn] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- case DLT_LOG_INFO:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;36m[" << con << "] [Info] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- default:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;32m[" << con << "] [Defa] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
- }
- }
-
- return true;
- }
- else
- {
- if (!context)
- {
- switch (loglevel)
- {
- case DLT_LOG_OFF:
- case DLT_LOG_FATAL:
- case DLT_LOG_ERROR:
- mNoDltContextData.buffer << "[DEF] [Erro] ";
- mLogOn = true;
- break;
- case DLT_LOG_WARN:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[DEF] [Warn] ";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- case DLT_LOG_INFO:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[DEF] [Info] ";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- default:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[DEF] [Defa] ";
- }
- else
- {
- mLogOn = false;
- }
- }
- }
- else
- {
- std::string con(mMapContext.at(context));
- switch (loglevel)
- {
- case DLT_LOG_OFF:
- case DLT_LOG_FATAL:
- case DLT_LOG_ERROR:
- mNoDltContextData.buffer << "[" << con << "] [Erro] ";
- mLogOn = true;
- break;
- case DLT_LOG_WARN:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[" << con << "] [Warn] ";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- case DLT_LOG_INFO:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[" << con << "] [Info] ";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- default:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[" << con << "] [Defa] ";
- }
- else
- {
- mLogOn = false;
- }
- }
- }
-
- return true;
- }
}
-#ifdef WITH_DLT
-CAmDltWrapper::CAmDltWrapper(const char *appid, const char *description, const bool debugEnabled, const logDestination logDest, const std::string Filename, bool onlyError)
- : mDebugEnabled(debugEnabled)
- , //
- mlogDestination(logDest)
- , //
- mFilename(NULL)
- , //
- mOnlyError(onlyError)
- , //
- mLogOn(true)
+CAmDltWrapper::~CAmDltWrapper()
{
- if (mDebugEnabled && mlogDestination == logDestination::DAEMON)
+ for (auto context : mMapContext)
{
- dlt_register_app(appid, description);
- // register a default context
- dlt_register_context(&mDltContext, "DEF", "Default Context registered by DLTWrapper Class");
+ unregisterContext(*(context.first));
}
- else if (mDebugEnabled)
- {
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- std::cout << "\033[0;36m[DLT] Registering AppID " << appid << " , " << description << "\033[0m" << std::endl;
- }
- else
- {
- mFilename.open(Filename, std::ofstream::out | std::ofstream::trunc);
- if (!mFilename.is_open())
- {
- throw std::runtime_error("Cannot open file for logging");
- }
- mFilename << now() << "[DLT] Registering AppID " << appid << " , " << description << std::endl;
- }
- }
-}
+ delete mpLogger;
+ mpLogger = NULL;
-CAmDltWrapper::~CAmDltWrapper()
-{
- if (mpDLTWrapper && mDebugEnabled && mlogDestination == logDestination::DAEMON)
- {
- mpDLTWrapper->unregisterContext(mDltContext);
- delete mpDLTWrapper;
- }
- else if (mpDLTWrapper && mDebugEnabled && mlogDestination == logDestination::COMMAND_LINE)
- {
- mFilename.close();
- }
+ mpDLTWrapper = NULL;
}
void CAmDltWrapper::unregisterContext(DltContext &handle)
{
- if (mDebugEnabled && mlogDestination == logDestination::DAEMON)
+ if (mpLogger)
{
- dlt_unregister_context(&handle);
+ string ctxID(handle.contextID, DLT_ID_SIZE);
+ mpLogger->unregisterContext(ctxID.c_str());
+ mMapContext.erase(&handle);
}
}
void CAmDltWrapper::deinit()
{
- if (mDebugEnabled)
+ if (mpCurrentContext)
{
- unregisterContext(mDltContext);
+ mpCurrentContext->configure(mOnlyError ? LL_ERROR : LL_INFO);
}
+ mpCurrentContext = NULL;
}
void CAmDltWrapper::registerContext(DltContext &handle, const char *contextid, const char *description)
{
- if (mDebugEnabled && mlogDestination == logDestination::DAEMON)
- {
- dlt_register_context(&handle, contextid, description);
- }
- else if (mDebugEnabled)
- {
- mMapContext.emplace(&handle, std::string(contextid));
-
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- std::cout << "\033[0;36m[DLT] Registering Context " << contextid << " , " << description << "\033[0m" << std::endl;
- }
- else
- {
- mFilename << now() << "[DLT] Registering Context " << contextid << " , " << description << std::endl;
- }
- }
-}
-
-void CAmDltWrapper::registerContext(DltContext &handle, const char *contextid, const char *description, const DltLogLevelType level, const DltTraceStatusType status)
-{
- if (mDebugEnabled && mlogDestination == logDestination::DAEMON)
- {
- dlt_register_context_ll_ts(&handle, contextid, description, level, status);
- }
- else if (mDebugEnabled)
+ if (mpLogger)
{
+ mpLogger->registerContext(contextid, description);
+ size_t len = min(DLT_ID_SIZE, 1 + (int)strlen(contextid));
+ strncpy(handle.contextID, contextid, len);
mMapContext.emplace(&handle, std::string(contextid));
-
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- std::cout << "\033[0;36m[DLT] Registering Context " << contextid << " , " << description << "\033[0m" << std::endl;
- }
- else
- {
- mFilename << now() << " [DLT] Registering Context " << contextid << " , " << description << std::endl;
- }
}
}
-bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext *context)
+void CAmDltWrapper::registerContext(DltContext &handle, const char *contextid, const char *description
+ , DltLogLevelType level, DltTraceStatusType status)
{
- pthread_mutex_lock(&mMutex);
- if (mlogDestination == logDestination::DAEMON)
+ if (mpLogger)
{
- if (!context)
+ if (level == DLT_LOG_DEFAULT)
{
- context = &mDltContext;
+ logWarning("CAmDltWrapper::registerContext - understanding DLT_LOG_DEFAULT as DLT_LOG_INFO");
+ level = DLT_LOG_INFO;
}
-
- if (dlt_user_log_write_start(context, &mDltContextData, loglevel) <= 0)
+ if (status == DLT_TRACE_STATUS_DEFAULT)
{
- pthread_mutex_unlock(&mMutex);
- return false;
+ logError("CAmDltWrapper::registerContext - understanding DLT_TRACE_STATUS_DEFAULT as DLT_TRACE_STATUS_ON");
+ status = DLT_TRACE_STATUS_ON;
}
- }
- else
- {
- initNoDlt(loglevel, context);
- }
-
- return true;
-}
-void CAmDltWrapper::send()
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_finish(&mDltContextData);
- }
- else
- {
- if (mlogDestination == logDestination::COMMAND_LINE && mLogOn)
- {
- std::cout << mNoDltContextData.buffer.str().c_str() << std::endl;
- }
- else if (mLogOn)
- {
- mFilename << now() << mNoDltContextData.buffer.str().c_str() << std::endl;
- }
-
- mNoDltContextData.buffer.str("");
- mNoDltContextData.buffer.clear();
- }
-
- pthread_mutex_unlock(&mMutex);
-}
-
-void CAmDltWrapper::append(const int8_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_int8(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const uint8_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_uint8(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const int16_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_int16(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const uint16_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_uint16(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const int32_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_int32(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const uint32_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_uint32(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const std::string &value)
-{
- append(value.c_str());
-}
-
-void CAmDltWrapper::append(const bool value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value));
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const int64_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_int64(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const uint64_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_uint64(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const std::vector<uint8_t> &data)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_raw(&mDltContextData, (void *)data.data(), data.size());
- }
- else
- {
- mNoDltContextData.buffer << data.data();
- }
-}
-
-}
-#else // ------------------------------------------------------------------------------------------------- no DLT !
-CAmDltWrapper::CAmDltWrapper(const char *appid, const char *description, const bool debugEnabled, const logDestination logDest, const std::string Filename, bool onlyError)
- : mDebugEnabled(debugEnabled)
- , //
- mlogDestination(logDest)
- , //
- mFilename(NULL)
- , //
- mOnlyError(onlyError)
- , //
- mLogOn(true)
-{
- if (logDest == logDestination::DAEMON)
- {
- std::cout << "\033[0;31m[DLT] Cannot Use Daemon Logging, active in CMAKE! Using CommandLine\033[0m" << std::endl;
- mlogDestination = logDestination::COMMAND_LINE;
- }
-
- if (mDebugEnabled)
- {
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- std::cout << "\033[0;36m[DLT] Registering AppID " << appid << " , " << description << "\033[0m" << std::endl;
- }
- else
- {
- mFilename.open(Filename, std::ofstream::out | std::ofstream::trunc);
- if (!mFilename.is_open())
- {
- throw std::runtime_error("Cannot open file for logging");
- }
-
- mFilename << now() << "[DLT] Registering AppID " << appid << " , " << description << std::endl;
- }
- }
-}
-
-CAmDltWrapper::~CAmDltWrapper()
-{
- if (mpDLTWrapper && mDebugEnabled && mlogDestination == logDestination::COMMAND_LINE)
- {
- mFilename.close();
- }
-}
-
-void CAmDltWrapper::unregisterContext(DltContext &handle)
-{
-}
-
-void CAmDltWrapper::deinit()
-{
-}
-
-void CAmDltWrapper::registerContext(DltContext &handle, const char *contextid, const char *description)
-{
- if (mDebugEnabled)
- {
+ size_t len = min(DLT_ID_SIZE, 1 + (int)strlen(contextid));
+ mpLogger->registerContext(contextid, description
+ , static_cast<am_LogLevel_e>(level), static_cast<am_LogStatus_e>(status));
+ strncpy(handle.contextID, contextid, len);
mMapContext.emplace(&handle, std::string(contextid));
-
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- std::cout << "\033[0;36m[DLT] Registering Context " << contextid << " , " << description << "\033[0m" << std::endl;
- }
- else
- {
- mFilename << now() << "[DLT] Registering Context " << contextid << " , " << description << std::endl;
- }
}
}
-void CAmDltWrapper::registerContext(DltContext &handle, const char *contextid, const char *description, const DltLogLevelType level, const DltTraceStatusType status)
+
+bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext *context)
{
- if (mDebugEnabled)
+ if (mpLogger)
{
- mMapContext.emplace(&handle, std::string(contextid));
-
- if (mlogDestination == logDestination::COMMAND_LINE)
+ if (context)
{
- std::cout << "\033[0;36m[DLT] Registering Context " << contextid << " , " << description << "\033[0m" << std::endl;
+ string mCurrentContextID(context->contextID, DLT_ID_SIZE);
+ mpCurrentContext = &(mpLogger->importContext(mCurrentContextID.c_str()));
}
else
{
- mFilename << now() << " [DLT] Registering Context " << contextid << " , " << description << std::endl;
+ mpCurrentContext = &(mpLogger->importContext());
}
+ mpCurrentContext->configure(static_cast<am_LogLevel_e>(loglevel));
}
-}
-bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext *context)
-{
- pthread_mutex_lock(&mMutex);
- return initNoDlt(loglevel, context);
+ return true;
}
void CAmDltWrapper::send()
{
- if (mlogDestination == logDestination::COMMAND_LINE && mLogOn)
+ if (mpCurrentContext)
{
- std::cout << mNoDltContextData.buffer.str().c_str() << std::endl;
+ mpCurrentContext->send();
}
- else if (mLogOn)
- {
- mFilename << now() << mNoDltContextData.buffer.str().c_str() << std::endl;
- }
-
- mNoDltContextData.buffer.str("");
- mNoDltContextData.buffer.clear();
- pthread_mutex_unlock(&mMutex);
-}
-
-void CAmDltWrapper::append(const int8_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const uint8_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const int16_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const uint16_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const int32_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const uint32_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const std::string &value)
-{
- append(value.c_str());
-}
-
-void CAmDltWrapper::append(const bool value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const int64_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const uint64_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const std::vector<uint8_t> &data)
-{
- mNoDltContextData.buffer << data.data();
+ mpCurrentContext = NULL;
}
}
-#endif // WITH_DLT
diff --git a/AudioManagerUtilities/src/CAmLogWrapper.cpp b/AudioManagerUtilities/src/CAmLogWrapper.cpp
new file mode 100755
index 0000000..8bd6b0a
--- /dev/null
+++ b/AudioManagerUtilities/src/CAmLogWrapper.cpp
@@ -0,0 +1,125 @@
+/**
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2017, ADIT GmbH
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ *
+ * \author Mattia Guerra, mguerra@de.adit-jv.com ADIT 2017
+ * \author Jens Lorenz, jlorenz@de.adit-jv.com ADIT 2017
+ *
+ * \file CAmLogWrapper.cpp
+ * For further information see http://www.genivi.org/.
+ *
+ */
+
+#include <iostream>
+#include <unistd.h>
+#include "CAmLogWrapper.h"
+#include "CAmLoggerStdOut.h"
+#include "CAmLoggerFile.h"
+#ifdef WITH_DLT
+# include "CAmLoggerDlt.h"
+#endif
+
+
+using namespace std;
+
+namespace am
+{
+
+IAmLogger *CAmLogWrapper::mpLogger = NULL;
+string CAmLogWrapper::mAppId = "";
+string CAmLogWrapper::mDescription = "";
+am_LogStatus_e CAmLogWrapper::mLogStatus = LS_ON;
+am_LogService_e CAmLogWrapper::mLogService = DEFAULT_LOG_SERVICE;
+string CAmLogWrapper::mFilename = "";
+bool CAmLogWrapper::mOnlyError = false;
+
+CAmLogWrapper::CAmLogWrapper(void)
+{
+}
+
+IAmLogger *CAmLogWrapper::instantiateOnce(const char *appid, const char *description,
+ const am_LogStatus_e logStatus, const am_LogService_e logService,
+ const string fileName, bool onlyError)
+{
+ if (mpLogger)
+ {
+ return mpLogger;
+ }
+
+ mAppId = string(appid);
+ mDescription = string(description);
+ mLogStatus = logStatus;
+ mLogService = logService;
+ mFilename = fileName;
+ mOnlyError = onlyError;
+ return instance(mLogService);
+}
+
+IAmLogger *CAmLogWrapper::instance(const am_LogService_e service)
+{
+ if (mpLogger)
+ {
+ return mpLogger;
+ }
+
+ switch (service)
+ {
+ case LOG_SERVICE_DLT:
+#ifdef WITH_DLT
+ mpLogger = new CAmLoggerDlt();
+#else
+ std::cerr << "Option WITH_DLT not enabled for CAmLogWrapper! "
+ << "Redirecting log output to stdout ..." << std::endl;
+ mLogService = LOG_SERVICE_STDOUT;
+ mpLogger = new CAmLoggerStdOut(mLogStatus, mOnlyError);
+#endif
+ break;
+ case LOG_SERVICE_STDOUT:
+ mpLogger = new CAmLoggerStdOut(mLogStatus, mOnlyError);
+ break;
+ case LOG_SERVICE_FILE:
+ mpLogger = new CAmLoggerFile(mLogStatus, mOnlyError, mFilename);
+ break;
+ default:
+ mpLogger = new CAmLoggerStdOut(LS_OFF);
+ break;
+ }
+
+ // an application seems not to use our CAmLogWrapper class properly therefore create default context
+ if ((mLogStatus == LS_ON) && mAppId.empty() && mDescription.empty())
+ {
+ mAppId = "AMDL";
+ std::ostringstream description;
+ description << "PID=" << getpid() << " _=" << getenv("_");
+ mDescription = description.str().c_str();
+ std::cerr << "Application doesn't call CAmLogWrapper::instantiateOnce!!!" << std::endl;
+ std::cerr << "-> CAmLogWrapper::instance registers DLT application [ AMDL | " << description.str() << " ]" << std::endl;
+ }
+
+ mpLogger->registerApp(mAppId.c_str(), mDescription.c_str());
+
+ return mpLogger;
+}
+
+CAmLogWrapper::~CAmLogWrapper()
+{
+ if (mpLogger)
+ {
+ mpLogger->unregisterApp();
+ delete mpLogger;
+ }
+}
+
+}
diff --git a/AudioManagerUtilities/src/CAmLoggerDlt.cpp b/AudioManagerUtilities/src/CAmLoggerDlt.cpp
new file mode 100755
index 0000000..8840916
--- /dev/null
+++ b/AudioManagerUtilities/src/CAmLoggerDlt.cpp
@@ -0,0 +1,223 @@
+/**
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2015, ADIT GmbH
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ *
+ * \author Jens Lorenz, jlorenz@de.adit-jv.com ADIT 2017
+ * \author Mattia Guerra, mguerra@de.adit-jv.com ADIT 2017
+ * \author Martin Koch, mkoch@de.adit-jv.com ADIT 2020
+ *
+ * \file CAmLoggerDlt.cpp
+ * For further information see http://www.genivi.org/.
+ *
+ */
+
+#include "CAmLogWrapper.h"
+#include "CAmLoggerDlt.h"
+
+namespace am
+{
+
+pthread_mutex_t gDltMtx = PTHREAD_MUTEX_INITIALIZER;
+
+CAmLogContextDlt::CAmLogContextDlt(const char *id)
+ : mId(id)
+{
+}
+
+DltContext *CAmLogContextDlt::getHandle()
+{
+ return &mDltContext;
+}
+
+void CAmLogContextDlt::append(const int8_t value)
+{
+ dlt_user_log_write_int8(&mDltContextData, value);
+}
+
+void CAmLogContextDlt::append(const uint8_t value)
+{
+ dlt_user_log_write_uint8(&mDltContextData, value);
+}
+
+void CAmLogContextDlt::append(const int16_t value)
+{
+ dlt_user_log_write_int16(&mDltContextData, value);
+}
+
+void CAmLogContextDlt::append(const uint16_t value)
+{
+ dlt_user_log_write_uint16(&mDltContextData, value);
+}
+
+void CAmLogContextDlt::append(const int32_t value)
+{
+ dlt_user_log_write_int32(&mDltContextData, value);
+}
+
+void CAmLogContextDlt::append(const uint32_t value)
+{
+ dlt_user_log_write_uint32(&mDltContextData, value);
+}
+
+void CAmLogContextDlt::append(const bool value)
+{
+ dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value));
+}
+
+void CAmLogContextDlt::append(const int64_t value)
+{
+ dlt_user_log_write_int64(&mDltContextData, value);
+}
+
+void CAmLogContextDlt::append(const uint64_t value)
+{
+ dlt_user_log_write_uint64(&mDltContextData, value);
+}
+
+void CAmLogContextDlt::append(const std::vector<uint8_t> &data)
+{
+ dlt_user_log_write_raw(&mDltContextData, (void *)data.data(), data.size());
+}
+
+void CAmLogContextDlt::append(const char *value)
+{
+ dlt_user_log_write_string(&mDltContextData, value);
+}
+
+bool CAmLogContextDlt::checkLogLevel(const am_LogLevel_e logLevel)
+{
+#ifdef DLT_IS_LOG_LEVEL_ENABLED
+ return (dlt_user_is_logLevel_enabled(&mDltContext, static_cast<DltLogLevelType>(logLevel)) == DLT_RETURN_TRUE);
+#else
+ (void)logLevel;
+ return true;
+#endif
+}
+
+bool CAmLogContextDlt::configure(const am_LogLevel_e loglevel)
+{
+ pthread_mutex_lock(&gDltMtx);
+
+ /* leave in case we are allowed to send messages */
+ if (dlt_user_log_write_start(&mDltContext, &mDltContextData, static_cast<DltLogLevelType>(loglevel)) > 0)
+ {
+ return true;
+ }
+
+ pthread_mutex_unlock(&gDltMtx);
+ return false;
+}
+
+void CAmLogContextDlt::send()
+{
+ dlt_user_log_write_finish(&mDltContextData);
+ pthread_mutex_unlock(&gDltMtx);
+}
+
+CAmLoggerDlt::~CAmLoggerDlt()
+{
+ unregisterApp();
+}
+
+void CAmLoggerDlt::registerApp(const char *appid, const char *description)
+{
+ dlt_register_app(appid, description);
+ registerContext(DEFAULT_CONTEXT, DEFAULT_DESCRIPTION);
+}
+
+void CAmLoggerDlt::unregisterApp()
+{
+ for (auto &&context : mCtxTable)
+ {
+ dlt_unregister_context(context.second->getHandle());
+ delete context.second;
+ delete context.first;
+ }
+ mCtxTable.clear();
+
+ dlt_unregister_app();
+}
+
+IAmLogContext &CAmLoggerDlt::registerContext(const char *contextid, const char *description)
+{
+ auto &&context = createContext(contextid);
+ dlt_register_context(context.getHandle(), contextid, description);
+ return context;
+}
+
+IAmLogContext &CAmLoggerDlt::registerContext(const char *contextid, const char *description, const am_LogLevel_e level, const am_LogStatus_e status)
+{
+ auto &&context = createContext(contextid);
+ dlt_register_context_ll_ts(context.getHandle(), contextid, description, static_cast<DltLogLevelType>(level), static_cast<DltTraceStatusType>(status));
+ return context;
+}
+
+IAmLogContext &CAmLoggerDlt::importContext(const char *contextid)
+{
+ // check, if we have this context
+ contextid = (contextid ? contextid : DEFAULT_CONTEXT);
+ for (auto &ctx : mCtxTable)
+ {
+ if (contextid && strncmp(ctx.first, contextid, DLT_ID_SIZE) == 0)
+ {
+ return *ctx.second;
+ }
+ }
+
+ // no match. Fall back to default context
+ return importContext(DEFAULT_CONTEXT);
+}
+
+void CAmLoggerDlt::unregisterContext(const char *contextid)
+{
+ for (auto it = mCtxTable.begin(); it != mCtxTable.end(); ++it)
+ {
+ if (contextid && strncmp(contextid, it->first, DLT_ID_SIZE) == 0)
+ {
+ dlt_unregister_context(it->second->getHandle());
+ delete it->second;
+
+ const char *pKey = it->first;
+ mCtxTable.erase(it);
+ delete pKey;
+
+ return;
+ }
+ }
+}
+
+CAmLogContextDlt &CAmLoggerDlt::createContext(const char *contextid)
+{
+ // check, if we already have this context
+ for (auto &ctx : mCtxTable)
+ {
+ if (contextid && strncmp(contextid, ctx.first, DLT_ID_SIZE) == 0)
+ {
+ return *ctx.second;
+ }
+ }
+
+ // Not in list. Create new
+ size_t len = (contextid ? strlen(contextid) : 0);
+ char *pKey = new char[1 + len];
+ strncpy(pKey, contextid, len);
+ pKey[len] = '\0';
+ auto *pContext = new CAmLogContextDlt(contextid);
+ mCtxTable[pKey] = pContext;
+
+ return *pContext;
+}
+
+}
diff --git a/AudioManagerUtilities/src/CAmLoggerFile.cpp b/AudioManagerUtilities/src/CAmLoggerFile.cpp
new file mode 100755
index 0000000..e3b4dbf
--- /dev/null
+++ b/AudioManagerUtilities/src/CAmLoggerFile.cpp
@@ -0,0 +1,252 @@
+/**
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2017, ADIT GmbH
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * \author Jens Lorenz, jlorenz@de.adit-jv.com ADIT 2017
+ * \author Mattia Guerra, mguerra@de.adit-jv.com ADIT 2017
+ * \author Martin Koch, mkoch@de.adit-jv.com ADIT 2020
+ *
+ * \file CAmLoggerFile.cpp
+ * For further information see http://www.genivi.org/.
+ *
+ */
+
+#include <algorithm>
+#include <iostream>
+#include <sstream>
+#include <mutex>
+#include <iomanip>
+#include "CAmLogWrapper.h"
+#include "CAmLoggerFile.h"
+#include "CAmTimeUtility.h"
+
+using namespace std;
+
+namespace am
+{
+
+#define PADDING_WIDTH 4
+
+pthread_mutex_t gFileMtx = PTHREAD_MUTEX_INITIALIZER;
+
+ostream &operator <<(ostream &out, const class CFileHeader &h)
+{
+ out << CAmTimeUtility::now() << "[" << setw(PADDING_WIDTH) << left << string(h.mCtx, 0, PADDING_WIDTH) << "] ";
+ return out;
+}
+
+CAmLogContextFile::CAmLogContextFile(const char *id, const am_LogLevel_e level, const am_LogStatus_e status, ofstream &filestream)
+ : mHeader(id)
+ , mLogLevel(level)
+ , mLogStatus(status)
+ , mFilestream(filestream)
+{
+}
+
+void CAmLogContextFile::append(const int8_t value)
+{
+ appendFile(value);
+}
+
+void CAmLogContextFile::append(const uint8_t value)
+{
+ appendFile(value);
+}
+
+void CAmLogContextFile::append(const int16_t value)
+{
+ appendFile(value);
+}
+
+void CAmLogContextFile::append(const uint16_t value)
+{
+ appendFile(value);
+}
+
+void CAmLogContextFile::append(const int32_t value)
+{
+ appendFile(value);
+}
+
+void CAmLogContextFile::append(const uint32_t value)
+{
+ appendFile(value);
+}
+
+void CAmLogContextFile::append(const uint64_t value)
+{
+ appendFile(value);
+}
+
+void CAmLogContextFile::append(const int64_t value)
+{
+ appendFile(value);
+}
+
+void CAmLogContextFile::append(const bool value)
+{
+ appendFile(value);
+}
+
+void CAmLogContextFile::append(const char *value)
+{
+ appendFile(value);
+}
+
+void CAmLogContextFile::append(const vector<uint8_t> &data)
+{
+ mFilestream << data.data() << " ";
+}
+
+template<class T>
+void CAmLogContextFile::appendFile(T value)
+{
+ mFilestream << value << " ";
+}
+
+bool CAmLogContextFile::configure(const am_LogLevel_e loglevel)
+{
+ if (LS_OFF || loglevel > mLogLevel)
+ {
+ return false;
+ }
+
+ pthread_mutex_lock(&gFileMtx);
+ mFilestream << mHeader;
+
+ return true;
+}
+
+bool CAmLogContextFile::checkLogLevel(const am_LogLevel_e logLevel)
+{
+ return logLevel <= mLogLevel;
+}
+
+void CAmLogContextFile::send()
+{
+ mFilestream << endl;
+ pthread_mutex_unlock(&gFileMtx);
+}
+
+CAmLoggerFile::CAmLoggerFile(const am_LogStatus_e status, const bool onlyError, const string &filename)
+ : mLogStatus(status)
+ , mStandardLogLevel(onlyError ? LL_ERROR : LL_INFO)
+{
+ if (mLogStatus == LS_OFF)
+ {
+ cout << "Running without Logging support" << endl;
+ return;
+ }
+
+ mFilestream.open(filename.c_str(), ofstream::out | ofstream::trunc);
+ if (!mFilestream.is_open())
+ {
+ throw runtime_error("Cannot open log file: " + filename);
+ }
+}
+
+CAmLoggerFile::~CAmLoggerFile()
+{
+ mFilestream.close();
+ unregisterApp();
+}
+
+void CAmLoggerFile::unregisterApp()
+{
+ for (auto &&context : mCtxTable)
+ {
+ unregisterContext(context.first);
+ }
+}
+
+void CAmLoggerFile::registerApp(const char *appid, const char *description)
+{
+ if (mLogStatus == LS_ON)
+ {
+ mFilestream << mHeader << "Register Application " << string(appid, PADDING_WIDTH) << ", " << description << endl;
+ }
+
+ registerContext(DEFAULT_CONTEXT, DEFAULT_DESCRIPTION);
+}
+
+IAmLogContext &CAmLoggerFile::registerContext(const char *contextid, const char *description)
+{
+ return registerContext(contextid, description, mStandardLogLevel, mLogStatus);
+}
+
+IAmLogContext &CAmLoggerFile::registerContext(const char *contextid, const char *description,
+ const am_LogLevel_e level, const am_LogStatus_e status)
+{
+ // check, if we already have this context
+ for (auto &ctx : mCtxTable)
+ {
+ if (contextid && strncmp(contextid, ctx.first, PADDING_WIDTH) == 0)
+ {
+ return *ctx.second;
+ }
+ }
+
+ // Not in list. Create new
+ if (mLogStatus == LS_ON)
+ {
+ mFilestream << mHeader << "Registering Context " << string(contextid, PADDING_WIDTH) << ", " << description << endl;
+ }
+ size_t len = (contextid ? strlen(contextid) : 0);
+ char *pKey = new char[1 + len];
+ strncpy(pKey, contextid, len);
+ pKey[len] = '\0';
+ auto *pContext = new CAmLogContextFile(contextid, level, status, mFilestream);
+ mCtxTable[pKey] = pContext;
+
+ return *pContext;
+}
+
+IAmLogContext &CAmLoggerFile::importContext(const char *contextid)
+{
+ // check, if we have this context
+ contextid = (contextid ? contextid : DEFAULT_CONTEXT);
+ for (auto &ctx : mCtxTable)
+ {
+ if (contextid && strncmp(ctx.first, contextid, PADDING_WIDTH) == 0)
+ {
+ return *ctx.second;
+ }
+ }
+
+ // no match. Fall back to default context
+ return importContext(DEFAULT_CONTEXT);
+}
+
+void CAmLoggerFile::unregisterContext(const char *contextid)
+{
+ for (auto it = mCtxTable.begin(); it != mCtxTable.end(); ++it)
+ {
+ if (contextid && strncmp(contextid, it->first, PADDING_WIDTH) == 0)
+ {
+ delete it->second;
+ const char *key = it->first;
+ mCtxTable.erase(it);
+ delete key;
+
+ if (mLogStatus == LS_ON)
+ {
+ mFilestream << mHeader << "Context " << string(contextid, PADDING_WIDTH) << "unregistered" << endl;
+ }
+
+ return;
+ }
+ }
+}
+
+}
diff --git a/AudioManagerUtilities/src/CAmLoggerStdOut.cpp b/AudioManagerUtilities/src/CAmLoggerStdOut.cpp
new file mode 100755
index 0000000..0e3e4dd
--- /dev/null
+++ b/AudioManagerUtilities/src/CAmLoggerStdOut.cpp
@@ -0,0 +1,264 @@
+/**
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2017, ADIT GmbH
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * \author Jens Lorenz, jlorenz@de.adit-jv.com ADIT 2017
+ * \author Mattia Guerra, mguerra@de.adit-jv.com ADIT 2017
+ * \author Martin Koch, mkoch@de.adit-jv.com ADIT 2020
+ *
+ * \file CAmLoggerStdOut.cpp
+ * For further information see http://www.genivi.org/.
+ *
+ */
+
+#include <algorithm>
+#include <iostream>
+#include <sstream>
+#include <mutex>
+#include <iomanip>
+#include "CAmLogWrapper.h"
+#include "CAmLoggerStdOut.h"
+#include "CAmTimeUtility.h"
+
+using namespace std;
+
+namespace am
+{
+
+#define PADDING_WIDTH 4
+
+pthread_mutex_t gStdOutMtx = PTHREAD_MUTEX_INITIALIZER;
+
+ostream &operator <<(ostream &out, const class CStdOutHeader &h)
+{
+ out << CAmTimeUtility::now() << h.mCc << "[" << setw(PADDING_WIDTH) << left << string(h.mCtx, 0, PADDING_WIDTH) << "] " << CC_RESET;
+ return out;
+}
+
+CAmLogContextStdOut::CAmLogContextStdOut(const char *id, const am_LogLevel_e level, const am_LogStatus_e status)
+ : mHeader(id, CC_GREEN)
+ , mLogLevel(level)
+ , mLogStatus(status)
+{
+}
+
+void CAmLogContextStdOut::changeLogLS(const am_LogLevel_e level, const am_LogStatus_e status)
+{
+ mLogLevel = level;
+ mLogStatus = status;
+}
+
+void CAmLogContextStdOut::append(const int8_t value)
+{
+ appendStdOut(value);
+}
+
+void CAmLogContextStdOut::append(const uint8_t value)
+{
+ appendStdOut(value);
+}
+
+void CAmLogContextStdOut::append(const int16_t value)
+{
+ appendStdOut(value);
+}
+
+void CAmLogContextStdOut::append(const uint16_t value)
+{
+ appendStdOut(value);
+}
+
+void CAmLogContextStdOut::append(const int32_t value)
+{
+ appendStdOut(value);
+}
+
+void CAmLogContextStdOut::append(const uint32_t value)
+{
+ appendStdOut(value);
+}
+
+void CAmLogContextStdOut::append(const uint64_t value)
+{
+ appendStdOut(value);
+}
+
+void CAmLogContextStdOut::append(const int64_t value)
+{
+ appendStdOut(value);
+}
+
+void CAmLogContextStdOut::append(const bool value)
+{
+ appendStdOut(value);
+}
+
+void CAmLogContextStdOut::append(const char *value)
+{
+ appendStdOut(value);
+}
+
+void CAmLogContextStdOut::append(const vector<uint8_t> &data)
+{
+ cout << data.data() << " ";
+}
+
+template<class T>
+void CAmLogContextStdOut::appendStdOut(T value)
+{
+ cout << value << " ";
+}
+
+bool CAmLogContextStdOut::configure(const am_LogLevel_e loglevel)
+{
+ if ((mLogStatus == LS_OFF) || (loglevel > mLogLevel))
+ {
+ return false;
+ }
+
+ pthread_mutex_lock(&gStdOutMtx);
+
+ switch (loglevel)
+ {
+ case LL_ERROR:
+ cout << mHeader << CC_RED;
+ break;
+ case LL_WARN:
+ cout << mHeader << CC_YELLOW;
+ break;
+ default:
+ cout << mHeader << CC_RESET;
+ break;
+ }
+
+ return true;
+}
+
+bool CAmLogContextStdOut::checkLogLevel(const am_LogLevel_e logLevel)
+{
+ return ((mLogStatus == LS_ON) && (logLevel <= mLogLevel));
+}
+
+void CAmLogContextStdOut::send()
+{
+ // NOTE: The color is set in the configure function
+ cout << CC_RESET << endl;
+ pthread_mutex_unlock(&gStdOutMtx);
+}
+
+CAmLoggerStdOut::CAmLoggerStdOut(const am_LogStatus_e status, const bool onlyError)
+ : mLogStatus(status)
+ , mStandardLogLevel(onlyError ? LL_ERROR : LL_INFO)
+{
+ if (mLogStatus == LS_OFF)
+ {
+ cout << mHeader << "Running without Logging support" << endl;
+ }
+}
+
+CAmLoggerStdOut::~CAmLoggerStdOut()
+{
+ unregisterApp();
+}
+
+void CAmLoggerStdOut::unregisterApp()
+{
+ for (auto &&context : mCtxTable)
+ {
+ unregisterContext(context.first);
+ }
+}
+
+void CAmLoggerStdOut::registerApp(const char *appid, const char *description)
+{
+ if (mLogStatus == LS_ON)
+ {
+ cout << mHeader << "Register Application " << string(appid, PADDING_WIDTH) << ", " << description << endl;
+ }
+
+ registerContext(DEFAULT_CONTEXT, DEFAULT_DESCRIPTION);
+}
+
+IAmLogContext &CAmLoggerStdOut::registerContext(const char *contextid, const char *description)
+{
+ return registerContext(contextid, description, mStandardLogLevel, mLogStatus);
+}
+
+IAmLogContext &CAmLoggerStdOut::registerContext(const char *contextid, const char *description,
+ const am_LogLevel_e level, const am_LogStatus_e status)
+{
+ // check, if we already have this context
+ for (auto &ctx : mCtxTable)
+ {
+ if (contextid && strncmp(contextid, ctx.first, PADDING_WIDTH) == 0)
+ {
+ ctx.second->changeLogLS(level, status);
+ return *ctx.second;
+ }
+ }
+
+ // Not in list. Create new
+ if (mLogStatus == LS_ON)
+ {
+ cout << mHeader << "Registering Context " << string(contextid, PADDING_WIDTH) << ", " << description << endl;
+ }
+ size_t len = (contextid ? strlen(contextid) : 0);
+ char *pKey = new char[1 + len];
+ strncpy(pKey, contextid, len);
+ pKey[len] = '\0';
+ auto *pContext = new CAmLogContextStdOut(contextid, level, status);
+ pContext->changeLogLS(level, status);
+ mCtxTable[pKey] = pContext;
+
+ return *pContext;
+}
+
+IAmLogContext &CAmLoggerStdOut::importContext(const char *contextid)
+{
+ // check, if we have this context
+ contextid = (contextid ? contextid : DEFAULT_CONTEXT);
+ for (auto &ctx : mCtxTable)
+ {
+ if (contextid && strncmp(ctx.first, contextid, PADDING_WIDTH) == 0)
+ {
+ return *ctx.second;
+ }
+ }
+
+ // no match. Fall back to default context
+ return importContext(DEFAULT_CONTEXT);
+}
+
+void CAmLoggerStdOut::unregisterContext(const char *contextid)
+{
+ for (auto it = mCtxTable.begin(); it != mCtxTable.end(); ++it)
+ {
+ if (contextid && strncmp(contextid, it->first, PADDING_WIDTH) == 0)
+ {
+ delete it->second;
+ const char *key = it->first;
+ mCtxTable.erase(it);
+ delete key;
+
+ if (mLogStatus == LS_ON)
+ {
+ cout << mHeader << string(contextid, PADDING_WIDTH) << " unregistered" << endl;
+ }
+
+ return;
+ }
+ }
+}
+
+}
diff --git a/AudioManagerUtilities/src/CAmSocketHandler.cpp b/AudioManagerUtilities/src/CAmSocketHandler.cpp
index 8f0cdb0..d657c7c 100644
--- a/AudioManagerUtilities/src/CAmSocketHandler.cpp
+++ b/AudioManagerUtilities/src/CAmSocketHandler.cpp
@@ -33,7 +33,7 @@
#include <csignal>
#include <cstring>
-#include "CAmDltWrapper.h"
+#include "CAmLogWrapper.h"
#include "CAmSocketHandler.h"
#ifdef WITH_TIMERFD
diff --git a/AudioManagerUtilities/src/CAmWatchdog.cpp b/AudioManagerUtilities/src/CAmWatchdog.cpp
index 3bac79c..5c64713 100644
--- a/AudioManagerUtilities/src/CAmWatchdog.cpp
+++ b/AudioManagerUtilities/src/CAmWatchdog.cpp
@@ -26,7 +26,7 @@
#include <cstdlib>
#include <stdexcept>
#include "audiomanagerconfig.h"
-#include "CAmDltWrapper.h"
+#include "CAmLogWrapper.h"
#include <systemd/sd-daemon.h>
namespace am