Skip to content

Commit d8efbe1

Browse files
committed
core/log: track default logging categories
Fixes a bug in fb37be7 which ignored default logging categories due to skipping QLoggingRegistry's filter.
1 parent 5d7e075 commit d8efbe1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+184
-79
lines changed

src/bluetooth/adapter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
#include <qstringliteral.h>
1313
#include <qtypes.h>
1414

15+
#include "../core/logcat.hpp"
1516
#include "../dbus/properties.hpp"
1617
#include "dbus_adapter.h"
1718

1819
namespace qs::bluetooth {
1920

2021
namespace {
21-
Q_LOGGING_CATEGORY(logAdapter, "quickshell.bluetooth.adapter", QtWarningMsg);
22+
QS_LOGGING_CATEGORY(logAdapter, "quickshell.bluetooth.adapter", QtWarningMsg);
2223
}
2324

2425
QString BluetoothAdapterState::toString(BluetoothAdapterState::Enum state) {

src/bluetooth/bluez.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <qobject.h>
99
#include <qtmetamacros.h>
1010

11+
#include "../core/logcat.hpp"
1112
#include "../dbus/dbus_objectmanager_types.hpp"
1213
#include "../dbus/objectmanager.hpp"
1314
#include "adapter.hpp"
@@ -16,7 +17,7 @@
1617
namespace qs::bluetooth {
1718

1819
namespace {
19-
Q_LOGGING_CATEGORY(logBluetooth, "quickshell.bluetooth", QtWarningMsg);
20+
QS_LOGGING_CATEGORY(logBluetooth, "quickshell.bluetooth", QtWarningMsg);
2021
}
2122

2223
Bluez* Bluez::instance() {
@@ -156,7 +157,12 @@ void Bluez::onInterfacesRemoved(const QDBusObjectPath& path, const QStringList&
156157
}
157158

158159
BluezQml::BluezQml() {
159-
QObject::connect(Bluez::instance(), &Bluez::defaultAdapterChanged, this, &BluezQml::defaultAdapterChanged);
160+
QObject::connect(
161+
Bluez::instance(),
162+
&Bluez::defaultAdapterChanged,
163+
this,
164+
&BluezQml::defaultAdapterChanged
165+
);
160166
}
161167

162168
} // namespace qs::bluetooth

src/bluetooth/bluez.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,21 @@ private slots:
5050
ObjectModel<BluetoothDevice> mDevices {this};
5151

5252
public:
53-
Q_OBJECT_BINDABLE_PROPERTY(Bluez, BluetoothAdapter*, bDefaultAdapter, &Bluez::defaultAdapterChanged);
53+
Q_OBJECT_BINDABLE_PROPERTY(
54+
Bluez,
55+
BluetoothAdapter*,
56+
bDefaultAdapter,
57+
&Bluez::defaultAdapterChanged
58+
);
5459
};
5560

5661
///! Bluetooth manager
5762
/// Provides access to bluetooth devices and adapters.
5863
class BluezQml: public QObject {
5964
Q_OBJECT;
65+
QML_NAMED_ELEMENT(Bluetooth);
66+
QML_SINGLETON;
67+
// clang-format off
6068
/// The default bluetooth adapter. Usually there is only one.
6169
Q_PROPERTY(BluetoothAdapter* defaultAdapter READ default NOTIFY defaultAdapterChanged BINDABLE bindableDefaultAdapter);
6270
QSDOC_TYPE_OVERRIDE(ObjectModel<qs::bluetooth::BluetoothAdapter>*);
@@ -66,8 +74,7 @@ class BluezQml: public QObject {
6674
/// A list of all connected bluetooth devices across all adapters.
6775
/// See @@BluetoothAdapter.devices for the devices connected to a single adapter.
6876
Q_PROPERTY(UntypedObjectModel* devices READ devices CONSTANT);
69-
QML_NAMED_ELEMENT(Bluetooth);
70-
QML_SINGLETON;
77+
// clang-format on
7178

7279
signals:
7380
void defaultAdapterChanged();

src/bluetooth/device.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <qtmetamacros.h>
1313
#include <qtypes.h>
1414

15+
#include "../core/logcat.hpp"
1516
#include "../dbus/properties.hpp"
1617
#include "adapter.hpp"
1718
#include "bluez.hpp"
@@ -20,7 +21,7 @@
2021
namespace qs::bluetooth {
2122

2223
namespace {
23-
Q_LOGGING_CATEGORY(logDevice, "quickshell.bluetooth.device", QtWarningMsg);
24+
QS_LOGGING_CATEGORY(logDevice, "quickshell.bluetooth.device", QtWarningMsg);
2425
}
2526

2627
QString BluetoothDeviceState::toString(BluetoothDeviceState::Enum state) {

src/core/colorquantizer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#include <qtmetamacros.h>
1919
#include <qtypes.h>
2020

21+
#include "logcat.hpp"
22+
2123
namespace {
22-
Q_LOGGING_CATEGORY(logColorQuantizer, "quickshell.colorquantizer", QtWarningMsg);
24+
QS_LOGGING_CATEGORY(logColorQuantizer, "quickshell.colorquantizer", QtWarningMsg);
2325
}
2426

2527
ColorQuantizerOperation::ColorQuantizerOperation(QUrl* source, qreal depth, qreal rescaleSize)

src/core/desktopentry.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
#include <ranges>
1818

1919
#include "common.hpp"
20+
#include "logcat.hpp"
2021
#include "model.hpp"
2122

2223
namespace {
23-
Q_LOGGING_CATEGORY(logDesktopEntry, "quickshell.desktopentry", QtWarningMsg);
24+
QS_LOGGING_CATEGORY(logDesktopEntry, "quickshell.desktopentry", QtWarningMsg);
2425
}
2526

2627
struct Locale {

src/core/generation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
#include "iconimageprovider.hpp"
2222
#include "imageprovider.hpp"
2323
#include "incubator.hpp"
24+
#include "logcat.hpp"
2425
#include "plugin.hpp"
2526
#include "qsintercept.hpp"
2627
#include "reload.hpp"
2728
#include "scan.hpp"
2829

2930
namespace {
30-
Q_LOGGING_CATEGORY(logScene, "scene");
31+
QS_LOGGING_CATEGORY(logScene, "scene");
3132
}
3233

3334
static QHash<const QQmlEngine*, EngineGeneration*> g_generations; // NOLINT

src/core/incubator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include "incubator.hpp"
22

33
#include <qlogging.h>
4-
#include <qloggingcategory.h>
54
#include <qqmlincubator.h>
65
#include <qtmetamacros.h>
76

8-
Q_LOGGING_CATEGORY(logIncubator, "quickshell.incubator", QtWarningMsg);
7+
#include "logcat.hpp"
8+
9+
QS_LOGGING_CATEGORY(logIncubator, "quickshell.incubator", QtWarningMsg);
910

1011
void QsQmlIncubator::statusChanged(QQmlIncubator::Status status) {
1112
switch (status) {

src/core/incubator.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#pragma once
22

3-
#include <qloggingcategory.h>
43
#include <qobject.h>
54
#include <qqmlincubator.h>
65
#include <qtmetamacros.h>
76

8-
Q_DECLARE_LOGGING_CATEGORY(logIncubator);
7+
#include "logcat.hpp"
8+
9+
QS_DECLARE_LOGGING_CATEGORY(logIncubator);
910

1011
class QsQmlIncubator
1112
: public QObject

src/core/logging.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@
3030
#include <sys/sendfile.h>
3131

3232
#include "instanceinfo.hpp"
33+
#include "logcat.hpp"
3334
#include "logging_p.hpp"
3435
#include "logging_qtprivate.cpp" // NOLINT
3536
#include "paths.hpp"
3637
#include "ringbuf.hpp"
3738

38-
Q_LOGGING_CATEGORY(logBare, "quickshell.bare");
39+
QS_LOGGING_CATEGORY(logBare, "quickshell.bare");
3940

4041
namespace qs::log {
4142
using namespace qt_logging_registry;
4243

43-
Q_LOGGING_CATEGORY(logLogging, "quickshell.logging", QtWarningMsg);
44+
QS_LOGGING_CATEGORY(logLogging, "quickshell.logging", QtWarningMsg);
4445

4546
bool LogMessage::operator==(const LogMessage& other) const {
4647
// note: not including time
@@ -187,10 +188,16 @@ void LogManager::filterCategory(QLoggingCategory* category) {
187188
// We don't respect log filters for qs logs because some distros like to ship
188189
// default configs that hide everything. QT_LOGGING_RULES is considered via the filter list.
189190
if (isQs) {
190-
filter.debug = instance->mDefaultLevel == QtDebugMsg;
191-
filter.info = instance->mDefaultLevel == QtInfoMsg;
192-
filter.warn = instance->mDefaultLevel == QtWarningMsg;
193-
filter.critical = instance->mDefaultLevel == QtCriticalMsg;
191+
// QtDebugMsg == 0, so default
192+
auto defaultLevel = instance->defaultLevels.value(categoryName);
193+
194+
filter = CategoryFilter();
195+
// clang-format off
196+
filter.debug = instance->mDefaultLevel == QtDebugMsg || defaultLevel == QtDebugMsg;
197+
filter.info = filter.debug || instance->mDefaultLevel == QtInfoMsg || defaultLevel == QtInfoMsg;
198+
filter.warn = filter.info || instance->mDefaultLevel == QtWarningMsg || defaultLevel == QtWarningMsg;
199+
filter.critical = filter.warn || instance->mDefaultLevel == QtCriticalMsg || defaultLevel == QtCriticalMsg;
200+
// clang-format on
194201
} else if (instance->lastCategoryFilter) {
195202
instance->lastCategoryFilter(category);
196203
filter = CategoryFilter(category);
@@ -262,6 +269,10 @@ void LogManager::init(
262269
qCDebug(logLogging) << "Logger initialized.";
263270
}
264271

272+
void initLogCategoryLevel(const char* name, QtMsgType defaultLevel) {
273+
LogManager::instance()->defaultLevels.insert(QLatin1StringView(name), defaultLevel);
274+
}
275+
265276
void LogManager::initFs() {
266277
QMetaObject::invokeMethod(
267278
&LogManager::instance()->threadProxy,

0 commit comments

Comments
 (0)