11 #define logDebug() LogMessage(LogMessage::DEBUG, __FILE__, __LINE__)
13 #define logInfo() LogMessage(LogMessage::INFO, __FILE__, __LINE__)
15 #define logWarn() LogMessage(LogMessage::WARNING, __FILE__, __LINE__)
17 #define logError() LogMessage(LogMessage::ERROR, __FILE__, __LINE__)
19 #ifdef __cpp_lib_stacktrace
21 #define logFatal() LogMessage(LogMessage::FATAL, __FILE__, __LINE__) << \
22 QString::fromStdString(std::to_string(std::stacktrace::current()))
24 #define logFatal() LogMessage(LogMessage::FATAL, __FILE__, __LINE__)
58 const QString &
file()
const;
A log-handler that dumps log-messages into files.
Definition: logger.hh:163
void setMinLevel(LogMessage::Level minLevel)
Resets the minimum log level.
Definition: logger.cc:218
LogMessage::Level minLevel() const
Returns the minimum log level.
Definition: logger.cc:213
QFile _file
The file to log into.
Definition: logger.hh:185
void handle(const LogMessage &message)
Callback to handle log messages.
Definition: logger.cc:223
QTextStream _stream
A reference to the text stream to log into.
Definition: logger.hh:187
FileLogHandler(const QString &file, LogMessage::Level minLevel=LogMessage::DEBUG, QObject *parent=nullptr)
Constructor.
Definition: logger.cc:181
LogMessage::Level _minLevel
The minimum log level.
Definition: logger.hh:189
virtual ~FileLogHandler()
Destructor, closes log file.
Definition: logger.cc:205
Interface for all log message handler.
Definition: logger.hh:79
virtual void handle(const LogMessage &message)=0
Callback to handle log messages.
LogHandler(QObject *parent=nullptr)
Constructor.
Definition: logger.cc:52
virtual ~LogHandler()
Destructor.
Definition: logger.cc:58
Implements a log-message.
Definition: logger.hh:32
Level _level
The log level.
Definition: logger.hh:66
QString _file
The source file.
Definition: logger.hh:68
int _line
The source line.
Definition: logger.hh:70
Level
Possible log-levels.
Definition: logger.hh:35
@ DEBUG
Level for debug messages. Will not be shown to the user unless requested.
Definition: logger.hh:36
@ FATAL
Level for fatal error messages.
Definition: logger.hh:40
@ INFO
Level for informative messages. Will not be shown to the user unless requested.
Definition: logger.hh:37
@ ERROR
Level for error messages.
Definition: logger.hh:39
@ WARNING
Level for warning messages.
Definition: logger.hh:38
virtual ~LogMessage()
Destructor.
Definition: logger.cc:24
QString _message
The log message content.
Definition: logger.hh:72
const QString & message() const
Returns the log message content.
Definition: logger.cc:44
Level level() const
Returns the level of the log message.
Definition: logger.cc:29
int line() const
Returns the source line.
Definition: logger.cc:39
const QString & file() const
Returns the source file.
Definition: logger.cc:34
LogMessage(Level level, const QString &file, int line, const QString &message="")
Constructor.
Definition: logger.cc:10
Singleton class to process log messages.
Definition: logger.hh:95
QList< LogHandler * > _handler
The list of registered log-handler.
Definition: logger.hh:125
static Logger * _instance
The singleton instance.
Definition: logger.hh:123
void onHandlerDeleted(QObject *obj)
Internal callback to handle deleted handler objects.
Definition: logger.cc:106
void addHandler(LogHandler *handler)
Adds a log-handler to the logger.
Definition: logger.cc:86
static Logger & get()
Factory method to get the singleton instance.
Definition: logger.cc:111
Logger()
Hidden constructor.
Definition: logger.cc:68
void remHandler(LogHandler *handler)
Removes a log-handler from the logger.
Definition: logger.cc:97
virtual ~Logger()
Destructor.
Definition: logger.cc:74
void log(const LogMessage &msg)
Logs a message.
Definition: logger.cc:79
A log-handler that dumps log-messages into a QTextStream.
Definition: logger.hh:132
LogMessage::Level minLevel() const
Returns the minimum log level.
Definition: logger.cc:129
void handle(const LogMessage &message)
Callback to handle log messages.
Definition: logger.cc:139
LogMessage::Level _minLevel
The minimum log level.
Definition: logger.hh:154
QTextStream & _stream
A reference to the text stream to log into.
Definition: logger.hh:152
void setMinLevel(LogMessage::Level minLevel)
Resets the minimum log level.
Definition: logger.cc:134
StreamLogHandler(QTextStream &stream, LogMessage::Level minLevel=LogMessage::DEBUG, bool color=false, QObject *parent=nullptr)
Constructor.
Definition: logger.cc:122
bool _color
If true, write messages using console colors.
Definition: logger.hh:156