As a project I am working on is getting bigger I am getting tired of writing comprehensive log messages, needed to find out what went wrong and where.
So it would be extremely useful if I can incorporate that information into the messages automatically. For C++ we have the convenient __FILE__
, __LINE__
and __FUNCTION__
macros, but I don't seem to find any for QML.
Note that there is console.trace()
which outputs a trace in the console in the following format:
onCompleted (qrc:/main.qml:72)
So it includes function, file and line, which is all I need, therefore I assume there already exists a way to get those. Natural, console.trace()
doesn't really quite cut it, because it directly outputs to the console, whereas I need those as strings to incorporate in my log messages.
So is there any way to get those?
Naturally I don't want to get them in the actual QML source, but the same way console.trace()
does - on the spot where my Log.error()
is invoked, so I can just Log.error("some error")
instead of Log.error("some error in " + file + ", at " + line + " while executing " + func)
which will actually be even more tedious than writing the whole thing manually.
Alternatively, I'd also appreciate if someone can point me to the implementation of the qml console
, because I combed through the entire qtdeclarative code base for "console" and found nothing.
Note that I already found this, however it isn't of use to me, because I need that for a specific subset of messages and don't want to override the default message handler for all output.