Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if (NOT (Qt5_FOUND OR Qt6_FOUND))
elseif(Qt5_FOUND)
message("Qt5 found.")
message(STATUS "Qt version is ${Qt5Core_VERSION}")
set(QT_MIN_VERSION 5.12.0)
set(QT_MIN_VERSION 5.9.0)
else()
message(FATAL_ERROR "No Qt found!")
endif()
Expand Down
9 changes: 1 addition & 8 deletions src/log4qt/helpers/patternformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,7 @@ QString LoggepatternConverter::convert(const LoggingEvent &loggingEvent) const
if (!loggingEvent.logger())
return QString();
QString name;

if (loggingEvent.logger() == LogManager::instance()->qtLogger()) // is qt logger
if (loggingEvent.categoryName().isEmpty())
name = LogManager::instance()->qtLogger()->name();
else
name = loggingEvent.categoryName();
else
name = loggingEvent.logger()->name();
name = loggingEvent.logger()->name();

if (mPrecision <= 0 || (name.isEmpty()))
return name;
Expand Down
4 changes: 2 additions & 2 deletions src/log4qt/log4qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@

#include <qglobal.h>

#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
# error "Log4Qt requires Qt version 5.12.0 or higher"
#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
# error "Log4Qt requires Qt version 5.9.0 or higher"
#endif

#if (defined(Q_CC_MSVC) && _MSC_VER < 1900)
Expand Down
14 changes: 10 additions & 4 deletions src/log4qt/logmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,18 @@ void LogManager::qtMessageHandler(QtMsgType type, const QMessageLogContext &cont
default:
level = Level::TRACE_INT;
}
LoggingEvent loggingEvent = LoggingEvent(instance()->qtLogger(),

QString categoryName = QStringLiteral("Qt");
if(context.category)
categoryName += QStringLiteral("::") + context.category;
categoryName = OptionConverter::classNameJavaToCpp(categoryName);
Logger* logger = instance()->qtLogger(categoryName);
LoggingEvent loggingEvent = LoggingEvent(logger,
level,
message,
MessageContext(context.file, context.line, context.function),
QStringLiteral("Qt ") % context.category);

instance()->qtLogger()->log(loggingEvent);
categoryName);
logger->log(loggingEvent);


// Qt fatal behaviour copied from global.cpp qt_message_output()
Expand All @@ -440,6 +445,7 @@ void LogManager::qtMessageHandler(QtMsgType type, const QMessageLogContext &cont
// } end
}


#ifdef Q_OS_WIN
static inline void convert_to_wchar_t_elided(wchar_t *d, size_t space, const char *s) Q_DECL_NOEXCEPT
{
Expand Down
6 changes: 3 additions & 3 deletions src/log4qt/logmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class LOG4QT_EXPORT LogManager
*
* \sa setHandleQtMessages()
*/
static Logger *qtLogger();
static Logger *qtLogger(const QString& category = QStringLiteral("Qt"));

static Logger *rootLogger();
static QList<Logger *> loggers();
Expand Down Expand Up @@ -333,9 +333,9 @@ inline Logger *LogManager::logLogger()
return logger(QStringLiteral("Log4Qt"));
}

inline Logger *LogManager::qtLogger()
inline Logger *LogManager::qtLogger(const QString &category)
{
return logger(QStringLiteral("Qt"));
return logger(category);
}

inline void LogManager::setHandleQtMessages(bool handleQtMessages)
Expand Down
18 changes: 16 additions & 2 deletions tests/log4qttest/log4qttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void Log4QtTest::PatternFormatter_data()
<< relative_string + " [main] DEBUG Test::TestLog4Qt foo.cpp:100 - foo() NDC - This is the message" + eol
<< 0;
QTest::newRow("TTCC conversion with file, line and method - Qt logger")
<< LoggingEvent(LogManager::instance()->qtLogger(),
<< LoggingEvent(LogManager::instance()->qtLogger(QStringLiteral("Qt::category")),
Level(Level::DEBUG_INT),
QStringLiteral("This is the message"),
QStringLiteral("NDC"),
Expand All @@ -291,7 +291,21 @@ void Log4QtTest::PatternFormatter_data()
QStringLiteral("Qt category")
)
<< "%r [%t] %p %c %F:%L-%M %x - %m%n"
<< relative_string + " [main] DEBUG Qt category foo.cpp:100-foo() NDC - This is the message" + eol
<< relative_string + " [main] DEBUG Qt::category foo.cpp:100-foo() NDC - This is the message" + eol
<< 0;
QTest::newRow("TTCC conversion with file, line and method - Qt logger java category name")
<< LoggingEvent(LogManager::instance()->qtLogger(QStringLiteral("Qt.category")),
Level(Level::DEBUG_INT),
QStringLiteral("This is the message"),
QStringLiteral("NDC"),
properties,
QStringLiteral("main"),
relative_timestamp,
MessageContext("foo.cpp", 100, "foo()"),
QStringLiteral("Qt.category")
)
<< "%r [%t] %p %c %F:%L-%M %x - %m%n"
<< relative_string + " [main] DEBUG Qt::category foo.cpp:100-foo() NDC - This is the message" + eol
<< 0;
QTest::newRow("TTCC conversion with file, line and method - Qt logger no category")
<< LoggingEvent(LogManager::instance()->qtLogger(),
Expand Down