Permalink
Browse files

Silence debug messages from Qt

* 99% of the messages we see are useless
* Debug output is driving OS X users nuts
  • Loading branch information...
1 parent 9f2c71c commit cf2c42d27f55c27a94c6e9763f7c2b07abbc1187 @jferris jferris committed Nov 7, 2013
Showing with 90 additions and 3 deletions.
  1. +57 −0 spec/driver_spec.rb
  2. +4 −3 src/WebPageManager.cpp
  3. +29 −0 src/main.cpp
View
@@ -2341,6 +2341,63 @@ def log
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
View
@@ -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() {
View
@@ -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

0 comments on commit cf2c42d

Please sign in to comment.