OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
qml_logger.hpp
1#pragma once
2#include <QObject>
3#include <QString>
4#include <QVariantMap>
5
6#include <ossia_export.h>
7
8#include <memory>
9#include <verdigris>
10namespace spdlog
11{
12class logger;
13}
14
15namespace ossia
16{
17struct websocket_threaded_connection;
18struct websocket_heartbeat;
19namespace qt
20{
21class OSSIA_EXPORT qml_logger : public QObject
22{
23 W_OBJECT(qml_logger)
24
25public:
26 enum log_level
27 {
28 Trace = 0,
29 Debug = 1,
30 Info = 2,
31 Warning = 3,
32 Error = 4,
33 Critical = 5
34 };
35 W_ENUM(log_level, Trace, Debug, Info, Warning, Error, Critical)
36
37 qml_logger();
38 ~qml_logger();
39
40 static qml_logger& instance();
41 QString appName() const;
42 QString appVersion() const;
43 QString appCreator() const;
44 QString loggerHost() const;
45 QStringList logFilter() const;
46
47 bool logQtMessages() const;
48
49 quint32 heartbeat() const;
50
51 log_level logLevel() const;
52
53public:
54 void appNameChanged(QString appName) E_SIGNAL(OSSIA_EXPORT, appNameChanged, appName);
55 void appVersionChanged(QString appVersion)
56 E_SIGNAL(OSSIA_EXPORT, appVersionChanged, appVersion);
57 void appCreatorChanged(QString appCreator)
58 E_SIGNAL(OSSIA_EXPORT, appCreatorChanged, appCreator);
59 void loggerHostChanged(QString loggerHost)
60 E_SIGNAL(OSSIA_EXPORT, loggerHostChanged, loggerHost);
61 void logQtMessagesChanged(bool logQtMessages)
62 E_SIGNAL(OSSIA_EXPORT, logQtMessagesChanged, logQtMessages);
63 void heartbeatChanged(quint32 heartbeat)
64 E_SIGNAL(OSSIA_EXPORT, heartbeatChanged, heartbeat);
65 void logLevelChanged(log_level logLevel)
66 E_SIGNAL(OSSIA_EXPORT, logLevelChanged, logLevel);
67 void logFilterChanged(const QStringList& logFilter)
68 E_SIGNAL(OSSIA_EXPORT, logFilterChanged, logFilter);
69 void filteredLog(int type, const QString& fileName, int line, const QString& msg)
70 E_SIGNAL(OSSIA_EXPORT, filteredLog, type, fileName, line, msg);
71
72public:
73 void connectLogger();
74 W_SLOT(connectLogger);
75 void disconnectLogger();
76 W_SLOT(disconnectLogger);
77
78 void setAppName(QString appName);
79 W_SLOT(setAppName);
80 void setAppVersion(QString appVersion);
81 W_SLOT(setAppVersion);
82 void setAppCreator(QString appCreator);
83 W_SLOT(setAppCreator);
84
85 void trace(const QString& s);
86 W_SLOT(trace);
87 void info(const QString& s);
88 W_SLOT(info);
89 void debug(const QString& s);
90 W_SLOT(debug);
91 void warning(const QString& s);
92 W_SLOT(warning);
93 void error(const QString& s);
94 W_SLOT(error);
95 void critical(const QString& s);
96 W_SLOT(critical);
97 void setLoggerHost(QString loggerHost);
98 W_SLOT(setLoggerHost);
99 void setLogQtMessages(bool logQtMessages);
100 W_SLOT(setLogQtMessages);
101 void setLogFilter(QStringList logFilter);
102 W_SLOT(setLogFilter);
103
104 void setHeartbeat(quint32 heartbeat);
105 W_SLOT(setHeartbeat);
106 void setLogLevel(log_level);
107 W_SLOT(setLogLevel);
108
109 void startHeartbeat(QVariantMap);
110 W_SLOT(startHeartbeat);
111
112private:
113 std::shared_ptr<websocket_threaded_connection> m_ws;
114 std::shared_ptr<spdlog::logger> m_logger;
115 std::shared_ptr<websocket_heartbeat> m_heartbeat;
116
117 QString m_appName;
118 QString m_appVersion;
119 QString m_appCreator;
120 QString m_loggerHost;
121 QStringList m_logFilter;
122
123 quint32 m_heartbeatDur{5};
124 log_level m_logLevel{Debug};
125 bool m_logQtMessages{};
126
127 W_PROPERTY(
128 QStringList, logFilter READ logFilter WRITE setLogFilter NOTIFY logFilterChanged)
129
130 W_PROPERTY(log_level, logLevel READ logLevel WRITE setLogLevel NOTIFY logLevelChanged)
131
132 W_PROPERTY(
133 bool, logQtMessages READ logQtMessages WRITE setLogQtMessages NOTIFY
134 logQtMessagesChanged)
135
136 W_PROPERTY(
137 quint32, heartbeat READ heartbeat WRITE setHeartbeat NOTIFY heartbeatChanged)
138
139 W_PROPERTY(
140 QString, loggerHost READ loggerHost WRITE setLoggerHost NOTIFY loggerHostChanged)
141
142 W_PROPERTY(
143 QString, appCreator READ appCreator WRITE setAppCreator NOTIFY appCreatorChanged,
144 W_Final)
145
146 W_PROPERTY(
147 QString, appVersion READ appVersion WRITE setAppVersion NOTIFY appVersionChanged,
148 W_Final)
149
150 W_PROPERTY(
151 QString, appName READ appName WRITE setAppName NOTIFY appNameChanged, W_Final)
152};
153}
154}
155W_REGISTER_ARGTYPE(ossia::qt::qml_logger::log_level)
log_level
Definition ossia-c.h:1637
Definition git_info.h:7
spdlog::logger & logger() noexcept
Where the errors will be logged. Default is stderr.
Definition context.cpp:118
bool critical
Means that the node is very important, e.g. a "play" message.
Definition node_attributes.hpp:92