This is the default logger for CamiTK. More...
#include <CamiTKLogger.h>
Public Member Functions | |
CamiTKLogger () | |
Default constructor. More... | |
bool | getDebugInformation () override |
QFileInfo | getLogFileInfo () override |
LogLevel | getLogLevel () override |
Get Current verbosity level of the log: More... | |
bool | getLogToFile () override |
check if the logger is currently writing on a file More... | |
bool | getLogToStandardOutput () override |
check if the logger is currently writing on standard output (std::cout) More... | |
LogLevel | getMessageBoxLevel () override |
bool | getTimeStampInformation () override |
QString | log (const QString msg, const LogLevel level, char const *fileName, char const *methodName, int lineNumber, const QObject *sender=nullptr) override final |
Log a message: If the logger is allowed to write on standard output, it will display the message (and timestamp) on the standard output If the logger is allowed to write on a file, it will also display the message in the log file. More... | |
void | setDebugInformation (bool) override |
Allows the logger to add debug information to the log message. More... | |
bool | setLogFileDirectory (QDir directoryName, bool moveExistingLogFile=true) override |
Set the specific directory to write to (default is the subdirectory "CamiTK" in the system temporary directory). More... | |
void | setLogLevel (LogLevel level) override |
Sets Current verbosity level of the log: More... | |
bool | setLogToFile (bool writeToFile) override |
Allows the logger to write to the log file. More... | |
void | setLogToStandardOutput (bool writeToStdOut) override |
Allows the logger to write on std::cout. More... | |
void | setMessageBoxLevel (LogLevel level) override |
Set the lowest log level that will open modal message box for messages instead of (silently/undisruptedly) write on std output. More... | |
void | setTimeStampInformation (bool showTimeStamp) override |
By default a logger should always show the time-stamp in the form of "yyyy-MM-dd HH:mm:ss.zzz" In test environment, reproducible log message might be prefered. More... | |
~CamiTKLogger () override | |
Destructor. More... | |
Public Member Functions inherited from camitk::InterfaceLogger | |
virtual | ~InterfaceLogger ()=default |
empty virtual destructor, to avoid memory leak More... | |
Protected Member Functions | |
virtual QString | buildLogMessage (QString message, LogLevel level, char const *fileName, char const *methodName, int lineNumber, const QObject *sender=nullptr) |
Builds a log message of correct format. More... | |
Additional Inherited Members | |
Public Types inherited from camitk::InterfaceLogger | |
enum | LogLevel { NONE = 0 , ERROR = 1 , WARNING = 2 , INFO = 3 , TRACE = 4 } |
: how chatty should the log output be... More... | |
This is the default logger for CamiTK.
This class implements InterfaceLogger with the following default parameters:
This way if the application or user decides to temporarily stop writing to the log file, all messages will be in the same file, even the one logged after the writing to the log file is resumed.
The log file name is "log-yyyy-MM-ddTHH-mm-ss.camitklog". The date/time format is based on ISO 8601 (as given by Qt::ISODate) with the difference that all ":" are replaced by "-", as ":" in file name does not always agree with Windows. The date/time It is based on the instantiation time (or the time the directory name was changed if is called after the instantiation)
The log file is permanently kept open for performance reason, and is flushed everytime a log message is appended for safety. This should cover all normal case (even application crash). However, this does not prevent an external process (or user) to truncate or remove the current file. The former will result in missing log message, the latter will result in a complete loss of all previous message and of all newer message.
Moreover, if the log macro is used inside a CamiTK inherited class (e.g., Action, Component,...) then message is prepend with a specific text (see below)
For example:
Action, Component, Viewer, Application, MainWindow, ComponentExtension and ActionExtension are currently supported.
camitk::CamiTKLogger::CamiTKLogger | ( | ) |
Default constructor.
References camitk::InterfaceLogger::NONE, and camitk::InterfaceLogger::WARNING.
|
override |
Destructor.
References log(), and camitk::InterfaceLogger::TRACE.
|
protectedvirtual |
Builds a log message of correct format.
References camitk::Log::getLevelAsString().
Referenced by log().
|
overridevirtual |
Implements camitk::InterfaceLogger.
|
overridevirtual |
Implements camitk::InterfaceLogger.
|
overridevirtual |
Get Current verbosity level of the log:
Implements camitk::InterfaceLogger.
|
overridevirtual |
check if the logger is currently writing on a file
Implements camitk::InterfaceLogger.
|
overridevirtual |
check if the logger is currently writing on standard output (std::cout)
Implements camitk::InterfaceLogger.
|
overridevirtual |
Implements camitk::InterfaceLogger.
|
overridevirtual |
Implements camitk::InterfaceLogger.
|
finaloverridevirtual |
Log a message: If the logger is allowed to write on standard output, it will display the message (and timestamp) on the standard output If the logger is allowed to write on a file, it will also display the message in the log file.
The level parameter gives the current message level that has to be compared with the logger level: if this level is greater or equals to the current log level, the current message will be logged.
Example: if the logger level is at WARNING, only ERROR and WARNING level messages will be displayed.
If in a static method or a non QObject class, then call this method with an empty last parameter.
Implements camitk::InterfaceLogger.
References buildLogMessage(), camitk::InterfaceLogger::ERROR, camitk::Log::getLevelAsString(), camitk::InterfaceLogger::INFO, camitk::InterfaceLogger::TRACE, and camitk::InterfaceLogger::WARNING.
Referenced by setDebugInformation(), setLogLevel(), setLogToFile(), setLogToStandardOutput(), setMessageBoxLevel(), setTimeStampInformation(), and ~CamiTKLogger().
|
overridevirtual |
Allows the logger to add debug information to the log message.
Debug information contains the filename, line number and method names where the log was called. Note that the exact content of the method name debug information depends on the compiler.
Implements camitk::InterfaceLogger.
References log(), and camitk::InterfaceLogger::TRACE.
|
overridevirtual |
Set the specific directory to write to (default is the subdirectory "CamiTK" in the system temporary directory).
If the directory does not exists it is going to be created.
If the log directory is different than the existing one:
directoryName | the new directory to use for the log file |
moveExistingLogFile | if true, the existing log file is move to the new directory and use to append the log messages from now. |
Implements camitk::InterfaceLogger.
|
overridevirtual |
Sets Current verbosity level of the log:
Implements camitk::InterfaceLogger.
References camitk::Log::getLevelAsString(), log(), and camitk::InterfaceLogger::TRACE.
|
overridevirtual |
Allows the logger to write to the log file.
By default, the directory to write to is the subdirectory "CamiTK" in the system temporary directory. The file name itself will be determined by the logger.
Implements camitk::InterfaceLogger.
References log(), and camitk::InterfaceLogger::TRACE.
|
overridevirtual |
Allows the logger to write on std::cout.
Implements camitk::InterfaceLogger.
References log(), and camitk::InterfaceLogger::TRACE.
|
overridevirtual |
Set the lowest log level that will open modal message box for messages instead of (silently/undisruptedly) write on std output.
Default value is NONE (too annoying).
Implements camitk::InterfaceLogger.
References camitk::Log::getLevelAsString(), log(), and camitk::InterfaceLogger::TRACE.
|
overridevirtual |
By default a logger should always show the time-stamp in the form of "yyyy-MM-dd HH:mm:ss.zzz" In test environment, reproducible log message might be prefered.
In this case the time stamp can be disabled.
showTimeStamp | if false the time stamp is not printed in log message. |
Implements camitk::InterfaceLogger.
References log(), and camitk::InterfaceLogger::TRACE.