MEONMedical / Log4Qt

Log4Qt - Logging for the Qt cross-platform application framework
Apache License 2.0
589 stars 235 forks source link

%M%F%L in properties file work wrong #37

Closed Wzshun closed 5 years ago

Wzshun commented 5 years ago

My env : log4qt-master, Qt 5.9.4, linux My log4qt.properties: logpath=./logs

log4j.reset=true log4j.Debug=WARN log4j.threshold=NULL log4j.handleQtMessages=true log4j.watchThisFile=false

log4j.rootLogger=ALL, daily

log4j.appender.daily=org.apache.log4j.DailyFileAppender log4j.appender.daily.file=${logpath}/emb.log log4j.appender.daily.appendFile=true log4j.appender.daily.datePattern=_yyyy-MM-dd log4j.appender.daily.keepDays=7 log4j.appender.daily.layout=org.apache.log4j.PatternLayout log4j.appender.daily.layout.conversionPattern=%d{yyyy-MM-dd hh:mm:ss.zzz} [%p]<%c> (%t)%F:%L%n %M: %m%n

My output: emb_2017-08-05.log: 2017-08-05 17:32:03.050 [DEBUG] (0x000000001b798e90):0 : ModbusThread mbStart 2017-08-05 17:32:05.550 [DEBUG] (0x000000001b798e90):0 : showWorkFile

My app.pro has DEFINES += QT_MESSAGELOGCONTEXT and log with qCDebug(embApp) << msg; or qDebug() << msg; in my source file.

How can i fix it?

andibacher commented 5 years ago

You have to use the macros l4qError(..), l4qError(..) for logging? file, line, and function are only set if you use this macros. If you log with: logger()->debug() << "Debug output"; or logger()->warn("Warning"); or ... file, line, and function are not set.

andibacher commented 5 years ago

Duplicate of #34

Wzshun commented 5 years ago

I think that find the reason why. I compile the log4qt as third party, and then in order to capture the context in qDebug/qWarning as on, you will need in log4qt.pro add DEFINES += QT_MESSAGELOGCONTEXT, and in my project this is also needed. I will verify it tomorrow, and give feedback here.

Wzshun commented 5 years ago

Fixed it! If you compile the log4qt as third party, you need add DEFINES += QT_MESSAGELOGCONTEXT in log4qt.pro. Also, you need add it in your pro which you want to capture context in release mode, if you doesn't see the context in logs, you will need to run qmake and rebuild your project.

I think that this should be added to build readme, if you want to build the log4qt as third party, using Qt internal QMessageLogContext and log4j.handleQtMessages=true.