Skip to content

Commit 80b29c0

Browse files
committed
Modify LogManager::qtLogger. Add Qt category paramter. QLoggingCategory can use adapters based on category.
1 parent 1dc0b05 commit 80b29c0

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/log4qt/helpers/patternformatter.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,7 @@ QString LoggepatternConverter::convert(const LoggingEvent &loggingEvent) const
664664
if (!loggingEvent.logger())
665665
return QString();
666666
QString name;
667-
668-
if (loggingEvent.logger() == LogManager::instance()->qtLogger()) // is qt logger
669-
if (loggingEvent.categoryName().isEmpty())
670-
name = LogManager::instance()->qtLogger()->name();
671-
else
672-
name = loggingEvent.categoryName();
673-
else
674-
name = loggingEvent.logger()->name();
667+
name = loggingEvent.logger()->name();
675668

676669
if (mPrecision <= 0 || (name.isEmpty()))
677670
return name;

src/log4qt/logmanager.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,19 @@ void LogManager::qtMessageHandler(QtMsgType type, const QMessageLogContext &cont
422422
default:
423423
level = Level::TRACE_INT;
424424
}
425-
LoggingEvent loggingEvent = LoggingEvent(instance()->qtLogger(),
425+
426+
QString categoryName = QStringLiteral("Qt::");
427+
if(context.category)
428+
categoryName += context.category;
429+
categoryName = OptionConverter::classNameJavaToCpp(categoryName);
430+
Logger* logger = instance()->qtLogger(categoryName);
431+
LoggingEvent loggingEvent = LoggingEvent(logger,
426432
level,
427433
message,
428434
MessageContext(context.file, context.line, context.function),
429-
QStringLiteral("Qt ") % context.category);
435+
categoryName);
430436

431-
instance()->qtLogger()->log(loggingEvent);
437+
instance()->qtLogger(categoryName)->log(loggingEvent);
432438

433439

434440
// Qt fatal behaviour copied from global.cpp qt_message_output()
@@ -440,6 +446,7 @@ void LogManager::qtMessageHandler(QtMsgType type, const QMessageLogContext &cont
440446
// } end
441447
}
442448

449+
443450
#ifdef Q_OS_WIN
444451
static inline void convert_to_wchar_t_elided(wchar_t *d, size_t space, const char *s) Q_DECL_NOEXCEPT
445452
{

src/log4qt/logmanager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class LOG4QT_EXPORT LogManager
116116
*
117117
* \sa setHandleQtMessages()
118118
*/
119-
static Logger *qtLogger();
119+
static Logger *qtLogger(const QString& category = QStringLiteral("Qt"));
120120

121121
static Logger *rootLogger();
122122
static QList<Logger *> loggers();
@@ -333,9 +333,9 @@ inline Logger *LogManager::logLogger()
333333
return logger(QStringLiteral("Log4Qt"));
334334
}
335335

336-
inline Logger *LogManager::qtLogger()
336+
inline Logger *LogManager::qtLogger(const QString &category)
337337
{
338-
return logger(QStringLiteral("Qt"));
338+
return logger(category);
339339
}
340340

341341
inline void LogManager::setHandleQtMessages(bool handleQtMessages)

0 commit comments

Comments
 (0)