13 #ifndef hifi_LogHandler_h
14 #define hifi_LogHandler_h
19 #include <QRecursiveMutex>
23 const int VERBOSE_LOG_INTERVAL_SECONDS = 5;
27 LogDebug = QtDebugMsg,
28 LogWarning = QtWarningMsg,
29 LogCritical = QtCriticalMsg,
30 LogFatal = QtFatalMsg,
60 bool parseOptions(
const QString& options,
const QString ¶mName);
122 QString
printMessage(LogMsgType type,
const QMessageLogContext& context,
const QString &message);
133 static void verboseMessageHandler(QtMsgType type,
const QMessageLogContext& context,
const QString &message);
135 int newRepeatedMessageID();
136 void printRepeatedMessage(
int messageID, LogMsgType type,
const QMessageLogContext& context,
const QString &message);
138 void setupRepeatedMessageFlusher();
165 void flushRepeatedMessages();
168 bool _shouldOutputProcessID {
false };
169 bool _shouldOutputThreadID {
false };
170 bool _shouldDisplayMilliseconds {
false };
171 bool _useColor {
false };
172 bool _keepRepeats {
false };
173 bool _useJournald {
false };
175 QString _previousMessage;
176 int _repeatCount { 0 };
179 int _currentMessageID { 0 };
180 struct RepeatedMessageRecord {
182 QString repeatString;
184 std::vector<RepeatedMessageRecord> _repeatedMessageRecords;
186 QStringList _breakMessages;
187 static QRecursiveMutex _mutex;
190 #define HIFI_FCDEBUG(category, message) \
192 if (category.isDebugEnabled()) { \
193 static int repeatedMessageID_ = LogHandler::getInstance().newRepeatedMessageID(); \
194 QString logString_; \
195 QDebug debugStringReceiver_(&logString_); \
196 debugStringReceiver_ << message; \
197 LogHandler::getInstance().printRepeatedMessage(repeatedMessageID_, LogDebug, QMessageLogContext(__FILE__, \
198 __LINE__, __func__, category().categoryName()), logString_); \
202 #define HIFI_FDEBUG(message) HIFI_FCDEBUG((*QLoggingCategory::defaultCategory()), message)
204 #define HIFI_FCDEBUG_ID(category, messageID, message) \
206 if (category.isDebugEnabled()) { \
207 QString logString_; \
208 QDebug debugStringReceiver_(&logString_); \
209 debugStringReceiver_ << message; \
210 LogHandler::getInstance().printRepeatedMessage(messageID, LogDebug, QMessageLogContext(__FILE__, \
211 __LINE__, __func__, category().categoryName()), logString_); \
215 #define HIFI_FDEBUG_ID(messageID, message) HIFI_FCDEBUG_ID((*QLoggingCategory::defaultCategory()), messageID, message)
Handles custom message handling and sending of stats/logs to Logstash instance.
Definition: LogHandler.h:40
void setShouldDisplayMilliseconds(bool shouldDisplayMilliseconds)
Set whether to display timestamps with milliseconds.
Definition: LogHandler.cpp:171
QString printMessage(LogMsgType type, const QMessageLogContext &context, const QString &message)
Process a log message.
Definition: LogHandler.cpp:211
static LogHandler & getInstance()
Returns the one instance of the LogHandler object.
Definition: LogHandler.cpp:42
bool isJournaldAvailable() const
Whether Journald is available on this version/system.
Definition: LogHandler.cpp:187
bool parseOptions(const QString &options, const QString ¶mName)
Parse logging options.
Definition: LogHandler.cpp:124
void setShouldOutputProcessID(bool shouldOutputProcessID)
Set whether to output the process ID.
Definition: LogHandler.cpp:161
void setShouldUseJournald(bool shouldUseJournald)
Set whether to use Journald, if it's available.
Definition: LogHandler.cpp:176
static void breakOnMessage(const char *str)
Break when a message that contains the specified string is logged.
Definition: LogHandler.cpp:386
static void verboseMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
A qtMessageHandler that can be hooked up to a target that links to Qt.
Definition: LogHandler.cpp:346
void setTargetName(const QString &targetName)
Set the name of the component that's producing log output.
Definition: LogHandler.cpp:156
void setShouldOutputThreadID(bool shouldOutputThreadID)
Set whether to output the thread ID.
Definition: LogHandler.cpp:166