aboutsummaryrefslogtreecommitdiffstats
path: root/src/geniviextras/qdltregistration.cpp
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2016-10-26 08:50:23 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2016-11-09 10:28:37 +0000
commit040b5aed0b395356fbd779bfd58e535a24c95fe6 (patch)
tree5c336c8b19fec081f70e5de35975f028285567d2 /src/geniviextras/qdltregistration.cpp
parent12cebc12e70b28709ed08777b289581c17583147 (diff)
QtGeniviExtras: Several DLT logging improvements
The DLT contexts are now registered with the log level matching the severity of the QtLoggingCategory, which is debug if nothing is specified. In addition it is now possible to delay the registration of the DLT context, until it is first used for logging. As an application might want to adapt the logging categories by parsing their own settings file. As DLT doesn't allow to change the log level from the client it's now possible to delay the creation until the client knows what loglevel is needed. The registerUnregisteredContexts() function can be used once all logging categories are defined, to forward the information to DLT. [ChangeLog] DLT context are now registered using the QtLoggingCategories severity Change-Id: I96cf0aa652b97a39b277718337cf1701388b1615 Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
Diffstat (limited to 'src/geniviextras/qdltregistration.cpp')
-rw-r--r--src/geniviextras/qdltregistration.cpp83
1 files changed, 68 insertions, 15 deletions
diff --git a/src/geniviextras/qdltregistration.cpp b/src/geniviextras/qdltregistration.cpp
index d98ef25..de922da 100644
--- a/src/geniviextras/qdltregistration.cpp
+++ b/src/geniviextras/qdltregistration.cpp
@@ -52,7 +52,6 @@ void qtGeniviLogLevelChangedHandler(char context_id[], uint8_t log_level, uint8_
globalDltRegistration()->d_ptr->dltLogLevelChanged(context_id, log_level, trace_status);
}
-
Q_GLOBAL_STATIC(QDltRegistration, dltRegistration)
QDltRegistration *globalDltRegistration()
@@ -65,19 +64,30 @@ QT_END_NAMESPACE
QDltRegistrationPrivate::QDltRegistrationPrivate(QDltRegistration *parent)
: q_ptr(parent)
, m_defaultContext(nullptr)
+ , m_registerOnFirstUse(false)
{
}
void QDltRegistrationPrivate::registerCategory(const QLoggingCategory *category, DltContext *dltContext, const char *dltCtxName, const char *dltCtxDescription)
{
- DLT_REGISTER_CONTEXT(*dltContext, dltCtxName, dltCtxDescription);
- m_categoryName2DltContext.insert(QString::fromLatin1(category->categoryName()), dltContext);
- m_ctxName2Category.insert(QString::fromLatin1(dltCtxName), const_cast<QLoggingCategory*>(category));
+ CategoryInfo info;
+ info.m_category = const_cast<QLoggingCategory*>(category);
+ info.m_ctxName = dltCtxName;
+ info.m_ctxDescription = dltCtxDescription;
+ info.m_context = dltContext;
+ if (!m_registerOnFirstUse) {
+ DLT_REGISTER_CONTEXT_LL_TS(*dltContext, dltCtxName, dltCtxDescription, category2dltLevel(category), DLT_TRACE_STATUS_DEFAULT);
#ifdef DLT_VERSION_2_12
- //TODO move to lamda once c++11 is ok to be used
- DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(*dltContext, &qtGeniviLogLevelChangedHandler);
+ //TODO move to lamda once c++11 is ok to be used
+ DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(*dltContext, &qtGeniviLogLevelChangedHandler);
#endif
+ info.m_registered = true;
+ } else {
+ info.m_registered = false;
+ }
+
+ m_categoryInfoHash.insert(QString::fromLatin1(category->categoryName()), info);
}
void QDltRegistrationPrivate::setDefaultContext(DltContext *dltContext)
@@ -88,10 +98,16 @@ void QDltRegistrationPrivate::setDefaultContext(DltContext *dltContext)
DltContext *QDltRegistrationPrivate::context(const char *categoryName)
{
const QString category = QString::fromLatin1(categoryName);
- if (!m_categoryName2DltContext.contains(category) && m_defaultContext)
+ if (!m_categoryInfoHash.contains(category) && m_defaultContext)
return m_defaultContext;
- return m_categoryName2DltContext.value(category);
+ CategoryInfo info = m_categoryInfoHash.value(category);
+ if (info.m_context && !info.m_registered) {
+ DLT_REGISTER_CONTEXT_LL_TS(*info.m_context, info.m_ctxName, info.m_ctxDescription, category2dltLevel(info.m_category), DLT_TRACE_STATUS_DEFAULT);
+ info.m_registered = true;
+ }
+
+ return info.m_context;
}
void QDltRegistrationPrivate::dltLogLevelChanged(char context_id[], uint8_t log_level, uint8_t trace_status)
@@ -99,8 +115,10 @@ void QDltRegistrationPrivate::dltLogLevelChanged(char context_id[], uint8_t log_
Q_Q(QDltRegistration);
Q_UNUSED(trace_status)
- const QString contextName = QString::fromLatin1(context_id);
- if (m_ctxName2Category.contains(contextName)) {
+ for (auto it = m_categoryInfoHash.begin(); it != m_categoryInfoHash.end(); ++it) {
+ if (it.value().m_ctxName != context_id)
+ continue;
+
QList<QtMsgType> msgTypes;
//Enable all QtLoggingCategories with a lower severity than the DLT level
@@ -136,7 +154,7 @@ void QDltRegistrationPrivate::dltLogLevelChanged(char context_id[], uint8_t log_
bool enabled = true;
if (!msgTypes.contains(type))
enabled = !enabled;
- QLoggingCategory* category = m_ctxName2Category.value(contextName);
+ QLoggingCategory* category = it.value().m_category;
if (category->isEnabled(type) != enabled) {
category->setEnabled(type, enabled);
q->logLevelChanged(category);
@@ -145,6 +163,24 @@ void QDltRegistrationPrivate::dltLogLevelChanged(char context_id[], uint8_t log_
}
}
+DltLogLevelType QDltRegistrationPrivate::category2dltLevel(const QLoggingCategory *category)
+{
+ DltLogLevelType logLevel = DLT_LOG_OFF;
+
+ if (category->isDebugEnabled())
+ logLevel = DLT_LOG_DEBUG;
+#if QT_VERSION >= 0x050500
+ else if (category->isInfoEnabled())
+ logLevel = DLT_LOG_INFO;
+#endif
+ else if (category->isWarningEnabled())
+ logLevel = DLT_LOG_WARN;
+ else if (category->isCriticalEnabled())
+ logLevel = DLT_LOG_ERROR;
+
+ return logLevel;
+}
+
QDltRegistration::QDltRegistration()
: d_ptr(new QDltRegistrationPrivate(this))
{
@@ -178,6 +214,23 @@ void QDltRegistration::setDefaultContext(const char *categoryName)
d->setDefaultContext(d->context(categoryName));
}
+void QDltRegistration::setRegisterContextOnFirstUseEnabled(bool enabled)
+{
+ Q_D(QDltRegistration);
+ d->m_registerOnFirstUse = enabled;
+}
+
+void QDltRegistration::registerUnregisteredContexts()
+{
+ Q_D(QDltRegistration);
+ for (auto it = d->m_categoryInfoHash.begin(); it != d->m_categoryInfoHash.end(); ++it) {
+ if (!it.value().m_registered) {
+ DLT_REGISTER_CONTEXT_LL_TS(*it.value().m_context, it.value().m_ctxName, it.value().m_ctxDescription, d->category2dltLevel(it.value().m_category), DLT_TRACE_STATUS_DEFAULT);
+ it.value().m_registered = true;
+ }
+ }
+}
+
void QDltRegistration::unregisterApplication()
{
Q_D(QDltRegistration);
@@ -191,16 +244,16 @@ void QDltRegistration::messageHandler(QtMsgType msgTypes, const QMessageLogConte
if (!dltCtx)
return;
- DltLogLevelType logLevel = DLT_LOG_INFO;
+ DltLogLevelType logLevel = DLT_LOG_OFF;
switch (msgTypes) {
case QtDebugMsg: logLevel = DLT_LOG_DEBUG; break;
- case QtWarningMsg: logLevel = DLT_LOG_WARN; break;
- case QtCriticalMsg: logLevel = DLT_LOG_ERROR; break;
- case QtFatalMsg: logLevel = DLT_LOG_FATAL; break;
#if QT_VERSION >= 0x050500
case QtInfoMsg: logLevel = DLT_LOG_INFO; break;
#endif
+ case QtWarningMsg: logLevel = DLT_LOG_WARN; break;
+ case QtCriticalMsg: logLevel = DLT_LOG_ERROR; break;
+ case QtFatalMsg: logLevel = DLT_LOG_FATAL; break;
}
DLT_LOG(*dltCtx, logLevel, DLT_STRING(qPrintable(qFormatLogMessage(msgTypes, msgCtx, msg))));