Qt: qDebug 등 출력 형식 맞 춤 형

Qt: qDebug 등 출력 형식 맞 춤 형

   
void testMessagePattern() {
    QString QT_MESSAGE_PATTERN=
            "[%{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}]"
            ": %{file}:%{line} - %{message}";
    qSetMessagePattern(QT_MESSAGE_PATTERN);
 
  
    qDebug() << "Hello Pattern";
    qDebug() << QString("  ").toUtf8().toHex();
}

   


[D]: /Users/Biao/Dropbox/workspace/Qt/Test/main.cpp:26 - Hello Pattern

[D]: /Users/Biao/Dropbox/workspace/Qt/Test/main.cpp:28 - "e9bb84e5bdaa"

void qSetMessagePattern(const QString & pattern)

Changes the output of the default message handler.

Allows to tweak the output of qDebug(), qWarning(), qCritical() and qFatal().

Following placeholders are supported:

Placeholder
Description
%{appname}
QCoreApplication::applicationName()
%{file}
Path to source file
%{function}
Function
%{line}
Line in source file
%{message}
The actual message
%{pid}
QCoreApplication::applicationPid()
%{threadid}
ID of current thread
%{type}
"debug", "warning", "critical" or "fatal"
You can also use conditionals on the type of the message using %{if-debug}, %{if-warning}, %{if-critical} or %{if-fatal} followed by an %{endif}. What is inside the%{if-*} and %{endif} will only be printed if the type matches.
Example:
QT_MESSAGE_PATTERN="[%{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}"
The default pattern is "%{message}".
The pattern can also be changed at runtime by setting the QT_MESSAGE_PATTERN environment variable; if both qSetMessagePattern() is called and QT_MESSAGE_PATTERN is set, the environment variable takes precedence.
qSetMessagePattern() has no effect if a custom message handler is installed.
This function was introduced in QtCore 5.0.
See also qInstallMessageHandler() and Debugging Techniques.

좋은 웹페이지 즐겨찾기