Skip to content

Commit 3d594e1

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 3d594e1

Some content is hidden

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

68 files changed

+212
-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/logcat.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <qlogging.h>
4+
#include <qloggingcategory.h>
5+
6+
namespace qs::log {
7+
void initLogCategoryLevel(const char* name, QtMsgType defaultLevel = QtDebugMsg);
8+
}
9+
10+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
11+
#define QS_DECLARE_LOGGING_CATEGORY(name) \
12+
namespace qslogcat { \
13+
Q_DECLARE_LOGGING_CATEGORY(name); \
14+
} \
15+
const QLoggingCategory& name()
16+
17+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
18+
#define QS_LOGGING_CATEGORY(name, category, ...) \
19+
namespace qslogcat { \
20+
Q_LOGGING_CATEGORY(name, category __VA_OPT__(, __VA_ARGS__)); \
21+
} \
22+
const QLoggingCategory& name() { \
23+
static auto* init = []() { \
24+
qs::log::initLogCategoryLevel(category __VA_OPT__(, __VA_ARGS__)); \
25+
return &qslogcat::name; \
26+
}(); \
27+
return (init) (); \
28+
}

0 commit comments

Comments
 (0)