Silence debug messages from Qt
* 99% of the messages we see are useless * Debug output is driving OS X users nuts
This commit is contained in:
parent
9f2c71c5d2
commit
cf2c42d27f
|
@ -2341,6 +2341,63 @@ describe Capybara::Webkit::Driver do
|
|||
end
|
||||
end
|
||||
|
||||
context 'Qt debug error app' do
|
||||
let(:app) do
|
||||
Class.new(Sinatra::Base) do
|
||||
get '/' do
|
||||
<<-HTML
|
||||
<html>
|
||||
<body>
|
||||
<div id="target">Loading</div>
|
||||
<script type="text/javascript">
|
||||
function causeMissingContentTypeWarning() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = function() {
|
||||
var target = document.getElementById('target');
|
||||
target.innerHTML = this.responseText;
|
||||
}
|
||||
xhr.open('post', '/ajax', false);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
causeMissingContentTypeWarning();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
HTML
|
||||
end
|
||||
|
||||
post '/ajax' do
|
||||
'Complete'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'silences Qt debug messages' do
|
||||
visit '/'
|
||||
wait_for_ajax_request
|
||||
log.should eq('')
|
||||
end
|
||||
|
||||
def wait_for_ajax_request
|
||||
driver.find_css('#target').first.text.should eq('Complete')
|
||||
end
|
||||
|
||||
let(:driver) do
|
||||
run_application app
|
||||
connection = Capybara::Webkit::Connection.new(:stderr => output)
|
||||
browser = Capybara::Webkit::Browser.new(connection)
|
||||
Capybara::Webkit::Driver.new(AppRunner.app, :browser => browser)
|
||||
end
|
||||
|
||||
let(:output) { StringIO.new }
|
||||
|
||||
def log
|
||||
output.rewind
|
||||
output.read
|
||||
end
|
||||
end
|
||||
|
||||
def driver_url(driver, path)
|
||||
URI.parse(driver.current_url).merge(path).to_s
|
||||
end
|
||||
|
|
|
@ -130,10 +130,11 @@ bool WebPageManager::isLoading() const {
|
|||
}
|
||||
|
||||
QDebug WebPageManager::logger() const {
|
||||
if (m_loggingEnabled)
|
||||
return qDebug();
|
||||
else
|
||||
if (m_loggingEnabled) {
|
||||
return qCritical();
|
||||
} else {
|
||||
return QDebug(m_ignoredOutput);
|
||||
}
|
||||
}
|
||||
|
||||
void WebPageManager::enableLogging() {
|
||||
|
|
29
src/main.cpp
29
src/main.cpp
|
@ -5,6 +5,12 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void ignoreDebugOutput(QtMsgType type, const char *msg);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
void ignoreDebugOutputQt5(QtMsgType type, const QMessageLogContext &context, const QString &message);
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
#ifdef Q_OS_UNIX
|
||||
if (setpgid(0, 0) < 0) {
|
||||
|
@ -18,6 +24,12 @@ int main(int argc, char **argv) {
|
|||
app.setOrganizationName("thoughtbot, inc");
|
||||
app.setOrganizationDomain("thoughtbot.com");
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
qInstallMessageHandler(ignoreDebugOutputQt5);
|
||||
#else
|
||||
qInstallMsgHandler(ignoreDebugOutput);
|
||||
#endif
|
||||
|
||||
Server server(0);
|
||||
|
||||
if (server.start()) {
|
||||
|
@ -29,3 +41,20 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
void ignoreDebugOutput(QtMsgType type, const char *msg) {
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
case QtWarningMsg:
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
void ignoreDebugOutputQt5(QtMsgType type, const QMessageLogContext &context, const QString &message) {
|
||||
Q_UNUSED(context);
|
||||
ignoreDebugOutput(type, message.toLocal8Bit().data());
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue