If you want to get that info for QML files and integrate it into the output, you can use
qInstallMessageHandler(QtMessageHandler handler)
to install your own message handler function. Inside that function you will have a QMessageLogContext
reference, which will give you access to more information, such as file name, line number, function name and so on.
void msgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
static QTextStream ts(stdout);
static const char * err[] = {"", "WARNING: ", "ERROR!: ", "FATAL: ", ""};
QString m = QString(err[type]) + context.category + "/" + context.file + "@" + QString::number(context.line) + "-" + context.function + ": " + msg;
ts << msg << endl;
}
Now, you may not want to process all messages in that manner, and limit it to some specific pattern, which can easily be achieved by incorporating a particular "header" in the message string and checking whether a particular message contains that or not, and proceed accordingly. For example:
console.log("test") // regular msg
console.log("?test") // custom msg handling
Naturally, you can use an array of headers to specify custom handling, save logs to different files, send network messages or emails in custom formats or whatever. Once you utilize a custom handler you can do with the messages whatever you want.