28 Q_MOC_INCLUDE(
"LogModel.h")
29 Q_MOC_INCLUDE(
"LogRemoteSink.h")
30 Q_MOC_INCLUDE(
"LogStore.h")
31 Q_MOC_INCLUDE(
"LogStoreQueryModel.h")
32 Q_PROPERTY(
LogModel* model READ model CONSTANT)
33 Q_PROPERTY(
LogRemoteSink* remoteSink READ remoteSink CONSTANT)
34 Q_PROPERTY(
LogStore* logStore READ logStore CONSTANT)
40 Q_PROPERTY(
bool diskCompressionEnabled READ isDiskCompressionEnabled WRITE setDiskCompressionEnabled NOTIFY
42 Q_PROPERTY(
int flushOnLevel READ flushOnLevel WRITE setFlushOnLevel NOTIFY
flushOnLevelChanged)
57 static LogManager* create(QQmlEngine* qmlEngine, QJSEngine* jsEngine);
58 static void installHandler();
59 static void applyEnvironmentLogLevel();
61 [[nodiscard]]
LogModel* model() {
return _model; }
63 [[nodiscard]]
LogRemoteSink* remoteSink() {
return _remoteSink; }
65 [[nodiscard]]
LogStore* logStore() {
return _logStore; }
69 [[nodiscard]]
bool hasError()
const {
return _ioError; }
71 [[nodiscard]] QString lastError()
const {
return _lastError; }
73 void setLogDirectory(
const QString& path);
75 [[nodiscard]] QString logDirectory()
const {
return _logDirectory; }
77 [[nodiscard]]
bool isDiskLoggingEnabled()
const {
return _diskLoggingEnabled; }
79 void setDiskLoggingEnabled(
bool enabled);
81 [[nodiscard]]
bool isDiskCompressionEnabled()
const {
return _diskCompressionEnabled; }
83 void setDiskCompressionEnabled(
bool enabled);
85 [[nodiscard]]
int flushOnLevel()
const {
return _flushOnLevel; }
87 void setFlushOnLevel(
int level);
89 Q_INVOKABLE
void writeMessages(
const QString& destFile, ExportFormat format = PlainText);
90 Q_INVOKABLE
void writeFilteredMessages(
const QString& destFile, ExportFormat format = PlainText);
91 Q_INVOKABLE
void clearError();
92 Q_INVOKABLE
void flush();
94 Q_INVOKABLE
static QStringList categoryLogLevelNames();
95 Q_INVOKABLE
static QVariantList categoryLogLevelValues();
97 static void setCaptureEnabled(
bool enabled);
98 static void clearCapturedMessages();
99 [[nodiscard]]
static QList<LogEntry> capturedMessages(
const QString& category = {});
100 [[nodiscard]]
static bool hasCapturedMessage(
const QString& category, LogEntry::Level level);
101 [[nodiscard]]
static bool hasCapturedWarning(
const QString& category);
102 [[nodiscard]]
static bool hasCapturedCritical(
const QString& category);
103 [[nodiscard]]
static bool hasCapturedUncategorizedMessage();
104 static void captureIfEnabled(QtMsgType type,
const QMessageLogContext& context,
const QString& msg);
116 void _handleEntry(
const LogEntry& entry);
120 explicit LogManager(QObject* parent =
nullptr);
122 static void msgHandler(QtMsgType type,
const QMessageLogContext& context,
const QString& msg);
123 void log(QtMsgType type,
const QMessageLogContext& context,
const QString& message);
124 static LogEntry buildEntry(QtMsgType type,
const QMessageLogContext& context,
const QString& message);
126 void _dispatchToSinks(
const LogEntry& entry);
128 void _setIoError(
const QString& message);
129 void _exportEntries(QList<LogEntry> entries,
const QString& destFile, ExportFormat format);
130 const QString& _internCategory(
const QString& category);
140 qint64 lastRefillMs = 0;
145 bool _rateLimitCheck(
const LogEntry& entry);
146 void _emitSuppressedSummary(
const QString& category,
int count);
148 QFuture<void> _exportFuture;
150 QList<LogEntry> _pendingDiskWrites;
151 QSet<QString> _internedCategories;
152 QHash<QString, RateBucket> _rateBuckets;
153 QString _logDirectory;
154 bool _ioError =
false;
156 bool _diskLoggingEnabled =
false;
157 bool _diskCompressionEnabled =
false;
158 int _flushOnLevel = LogEntry::Warning;
160 static constexpr int kMaxLogFileSize = 10 * 1024 * 1024;
161 static constexpr int kMaxBackupFiles = 5;
162 static constexpr int kFlushIntervalMSecs = 1000;
163 static constexpr int kRateTokensPerSecond = 100;
164 static constexpr int kRateMaxTokens = 200;