Skip to content

Commit

Permalink
Switch to using logging categories
Browse files Browse the repository at this point in the history
This changes the debug output to use logging categories. It also
provides a new DEVELOPMENT_BUILD define that exposes potentially more
sensitive logging info such as URLs only when it's set.
  • Loading branch information
llewelld committed Sep 24, 2019
1 parent 0b41a71 commit 07a6884
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 105 deletions.
3 changes: 3 additions & 0 deletions qmlplugin5/main.cpp
@@ -1,4 +1,7 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (c) 2013 - 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
35 changes: 23 additions & 12 deletions src/qmozcontext.cpp
@@ -1,5 +1,9 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-*/
/* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (c) 2013 - 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

Expand All @@ -26,6 +30,8 @@
#include "mozilla/embedlite/EmbedLiteView.h"
#include "mozilla/embedlite/EmbedInitGlue.h"

Q_LOGGING_CATEGORY(lcEmbedLiteExt, "org.sailfishos.embedliteext", QtWarningMsg)

using namespace mozilla::embedlite;

Q_GLOBAL_STATIC(QMozContext, mozContextInstance)
Expand All @@ -47,7 +53,7 @@ QMozContextPrivate::QMozContextPrivate(QObject *parent)
, mViewCreator(NULL)
, mMozWindow(NULL)
{
LOGT("Create new Context: %p, parent:%p", (void *)this, (void *)parent);
qCDebug(lcEmbedLiteExt) << "Create new Context:" << (void *)this << ", parent:" << (void *)parent;
setenv("BUILD_GRE_HOME", BUILD_GRE_HOME, 1);
LoadEmbedLite();
mApp = XRE_GetEmbedLite();
Expand All @@ -65,7 +71,7 @@ QMozContextPrivate::~QMozContextPrivate()
bool QMozContextPrivate::ExecuteChildThread()
{
if (!getenv("GECKO_THREAD")) {
LOGT("Execute in child Native thread: %p", (void *)mThread);
qCDebug(lcEmbedLiteExt) << "Execute in child Native thread:" << (void *)mThread;
GeckoWorker *worker = new GeckoWorker(mApp);

connect(mThread, SIGNAL(started()), worker, SLOT(doWork()));
Expand All @@ -83,7 +89,7 @@ bool QMozContextPrivate::ExecuteChildThread()
bool QMozContextPrivate::StopChildThread()
{
if (mThread && !mThread->isFinished()) {
LOGT("Stop Native thread: %p", (void *)mThread);
qCDebug(lcEmbedLiteExt) << "Stop Native thread:" << (void *)mThread;
mThread->exit(0);
mThread->wait();
return true;
Expand Down Expand Up @@ -114,7 +120,9 @@ void QMozContextPrivate::Initialized()
// App Destroyed, and ready to delete and program exit
void QMozContextPrivate::Destroyed()
{
LOGT("");
#ifdef DEVELOPMENT_BUILD
qCInfo(lcEmbedLiteExt);
#endif
mApp->SetListener(nullptr);

if (!mThread->isFinished()) {
Expand All @@ -130,7 +138,7 @@ void QMozContextPrivate::Destroyed()

void QMozContextPrivate::OnObserve(const char *aTopic, const char16_t *aData)
{
// LOGT("aTopic: %s, data: %s", aTopic, NS_ConvertUTF16toUTF8(aData).get());
//qCDebug(lcEmbedLiteExt) << "aTopic:" << aTopic << ", data:" << NS_ConvertUTF16toUTF8(aData).get();
QString data((QChar *)aData);
if (!data.startsWith('{') && !data.startsWith('[') && !data.startsWith('"')) {
QVariant vdata = QVariant::fromValue(data);
Expand All @@ -143,10 +151,13 @@ void QMozContextPrivate::OnObserve(const char *aTopic, const char16_t *aData)
ok = error.error == QJsonParseError::NoError;
QVariant vdata = doc.toVariant();
if (ok) {
// LOGT("mesg:%s, data:%s", aTopic, data.toUtf8().data());
//qCDebug(lcEmbedLiteExt) << "mesg:" << aTopic << ", data:" << data.toUtf8().data();
Q_EMIT recvObserve(aTopic, vdata);
} else {
LOGT("parse: s:'%s', err:%s, errLine:%i", data.toUtf8().data(), error.errorString().toUtf8().data(), error.offset);
qCDebug(lcEmbedLiteExt) << "JSON parse error:" << error.errorString().toUtf8().data();
#ifdef DEVELOPMENT_BUILD
qCDebug(lcEmbedLiteExt) << "parse: s:'" << data.toUtf8().data() << "', errLine:" << error.offset;
#endif
}
}

Expand All @@ -168,7 +179,7 @@ bool QMozContextPrivate::IsInitialized()
uint32_t QMozContextPrivate::CreateNewWindowRequested(const uint32_t &chromeFlags, const char *uri, const uint32_t &contextFlags,
EmbedLiteView *aParentView)
{
LOGT("QtMozEmbedContext new Window requested: parent:%p", (void *)aParentView);
qCDebug(lcEmbedLiteExt) << "QtMozEmbedContext new Window requested: parent:" << (void *)aParentView;
uint32_t viewId = QMozContext::instance()->createView(QString(uri), aParentView ? aParentView->GetUniqueID() : 0);
return viewId;
}
Expand Down Expand Up @@ -334,13 +345,13 @@ QMozContext::GetApp()

void QMozContext::setPixelRatio(float ratio)
{
qDebug() << "QMozContext::setPixelRatio is deprecated and will be removed 1st of December 2016. Use QMozEngineSettings::setPixelRatio instead.";
qCWarning(lcEmbedLiteExt) << "QMozContext::setPixelRatio is deprecated and will be removed 1st of December 2016. Use QMozEngineSettings::setPixelRatio instead.";
QMozEngineSettings::instance()->setPixelRatio(ratio);
}

float QMozContext::pixelRatio() const
{
qDebug() << "QMozContext::pixelRatio is deprecated and will be removed 1st of December 2016. Use QMozEngineSettings::pixelRatio instead.";
qCWarning(lcEmbedLiteExt) << "QMozContext::pixelRatio is deprecated and will be removed 1st of December 2016. Use QMozEngineSettings::pixelRatio instead.";
return QMozEngineSettings::instance()->pixelRatio();
}

Expand Down
2 changes: 1 addition & 1 deletion src/qmozembed.pri
Expand Up @@ -33,7 +33,7 @@ contains(CONFIG, with-system-nspr) {

LIBS += -L$$GECKO_LIB_DIR -lxpcomglue -Wl,--whole-archive -lmozglue -lmemory
LIBS += -Wl,--no-whole-archive -rdynamic -ldl
PKGCONFIG += nspr pixman-1
PKGCONFIG += nspr pixman-1 systemsettings

DEFINES += BUILD_GRE_HOME=\"\\\"$$BIN_DIR\\\"\"

Expand Down
26 changes: 9 additions & 17 deletions src/qmozembedlog.h
@@ -1,28 +1,20 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (c) 2013 - 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef QMOZ_EMBED_LOG_H
#define QMOZ_EMBED_LOG_H

#include <stdio.h>
#include <QDebug>
#include <QLoggingCategory>

#ifdef Q_DEBUG_LOG
//#define DEVELOPMENT_BUILD (1)

#ifdef LOG_COMPONENT
#define LOGT(FMT, ...) fprintf(stderr, \
"EmbedLiteExt %s:%s:%d: " FMT "\n", LOG_COMPONENT, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#else // LOG_COMPONENT
#define LOGT(FMT, ...) fprintf(stderr, \
"EmbedLiteExt %s:%d: " FMT "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
#endif // LOG_COMPONENT

#else // Q_DEBUG_LOG

#define LOGT(...) do {} while (0)

#endif // Q_DEBUG_LOG
Q_DECLARE_LOGGING_CATEGORY(lcEmbedLiteExt)

#endif // QMOZ_EMBED_LOG_H
20 changes: 9 additions & 11 deletions src/qmozenginesettings.cpp
@@ -1,11 +1,9 @@
/****************************************************************************
**
** Copyright (C) 2016 Jolla Ltd.
** Contact: Raine Makelainen <raine.makelainen@jolla.com>
**
****************************************************************************/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-*/
/* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (c) 2016 - 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

Expand Down Expand Up @@ -118,10 +116,10 @@ void QMozEngineSettingsPrivate::enableLowPrecisionBuffers(bool enabled)

void QMozEngineSettingsPrivate::setPreference(const QString &key, const QVariant &value)
{
LOGT("name:%s, type:%i", key.toUtf8().data(), value.type());
qCDebug(lcEmbedLiteExt) << "name:" << key.toUtf8().data() << ", type:" << value.type();

if (!isInitialized()) {
LOGT("Error: context not yet initialized");
qCDebug(lcEmbedLiteExt) << "Error: context not yet initialized";
mPreferences.insert(key, value);
return;
}
Expand Down Expand Up @@ -149,7 +147,7 @@ void QMozEngineSettingsPrivate::setPreference(const QString &key, const QVariant
}
break;
default:
LOGT("Unknown pref type: %i", value.type());
qCWarning(lcEmbedLiteExt) << "Unknown pref type:" << value.type();
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/qmozgrabresult.cpp
@@ -1,14 +1,18 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (c) 2015 - 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "qmozembedlog.h"
#include "qopenglwebpage.h"
#include "qmozgrabresult.h"
#include "qmozwindow.h"

#include <QCoreApplication>
#include <QDebug>
#if defined(QT_OPENGL_ES_2)
#include <QOpenGLFunctions_ES2>
#else
Expand Down
11 changes: 7 additions & 4 deletions src/qmozsecurity.cpp
@@ -1,9 +1,11 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <QDebug>
#include <QQueue>

#include <nsIWebProgressListener.h>
Expand All @@ -14,6 +16,7 @@
#include <nsStringAPI.h>
#include <systemsettings/certificatemodel.h>

#include "qmozembedlog.h"
#include "qmozsecurity.h"

// Ensure the enum values in QMozSecurity match the enum values in nsISSLStatus
Expand Down Expand Up @@ -236,7 +239,7 @@ void QMozSecurity::importState(const char *aStatus, unsigned int aState)
rv = serialHelper->DeserializeObject(serSSLStatus, getter_AddRefs(infoObj));

if (!NS_SUCCEEDED(rv)) {
qDebug() << "Security state change: deserialisation failed";
qCDebug(lcEmbedLiteExt) << "Security state change: deserialisation failed";
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/qmozsecurity.h
@@ -1,5 +1,8 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

Expand Down
9 changes: 9 additions & 0 deletions src/qmozview_defined_wrapper.h
@@ -1,3 +1,12 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (c) 2013 - 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef qmozview_defined_wrapper_h
#define qmozview_defined_wrapper_h

Expand Down

0 comments on commit 07a6884

Please sign in to comment.