Computer Assited Medical Intervention Tool Kit  version 4.1
CamiTKLogger.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 #ifndef CAMITKLOGGER_H
27 #define CAMITKLOGGER_H
28 
29 // -- Core stuff
30 #include "CamiTKAPI.h"
31 #include "InterfaceLogger.h"
32 
33 // -- Qt stuff
34 #include <QDir>
35 #include <QDateTime>
36 class QFile;
37 class QTextStream;
38 
39 namespace camitk {
40 
123 class CAMITK_API CamiTKLogger : public InterfaceLogger {
124 
125 public :
127  CamiTKLogger();
128 
130  ~CamiTKLogger() override;
131 
134  LogLevel getLogLevel() override;
135 
138  void setLogLevel(LogLevel level) override;
139 
142  void setLogToStandardOutput(bool writeToStdOut) override;
143 
147  bool getLogToStandardOutput() override;
148 
156  bool setLogToFile(bool writeToFile) override;
157 
174  bool setLogFileDirectory(QDir directoryName, bool moveExistingLogFile = true) override;
175 
177  bool getLogToFile() override;
178 
180  QFileInfo getLogFileInfo() override;
181 
187  void setMessageBoxLevel(LogLevel level) override;
188 
190  LogLevel getMessageBoxLevel() override;
191 
196  void setDebugInformation(bool) override;
197 
199  bool getDebugInformation() override;
200 
206  void setTimeStampInformation(bool showTimeStamp) override;
207 
209  bool getTimeStampInformation() override;
210 
222  QString log(const QString msg, const LogLevel level, char const* fileName, char const* methodName, int lineNumber, const QObject* sender = nullptr) override;
223 
224 
225 protected:
227  virtual QString buildLogMessage(QString message, LogLevel level, char const* fileName, char const* methodName, int lineNumber, const QObject* sender = nullptr);
228 
229 private:
231  QString getCamiTKAPIInformation(const QObject* sender);
232 
234  bool openLogFile(bool moveFile = false, QFileInfo fileToMove = QFileInfo());
235 
237  void closeLogFile();
238 
241 
243  InterfaceLogger::LogLevel messageBoxLevel;
244 
246  bool logToStdOut;
247 
249  bool logToFile;
250 
252  bool displayDebugInformation;
253 
255  bool displayTimeStampInformation;
256 
258  QDir logFileDirectory;
259 
261  QFile* logFile;
262 
264  QTextStream* logStream;
265 
267  QDateTime logStartTime;
268 
269 };
270 
271 }
272 
273 #endif // CAMITKLOGGER_H
camitk::CamiTKLogger::CamiTKLogger
CamiTKLogger()
Default constructor.
Definition: CamiTKLogger.cpp:70
camitk::CamiTKLogger::logFile
QFile * logFile
Current log file (the stream is flushed log message by log message)
Definition: CamiTKLogger.h:260
camitk::CamiTKLogger::logToStdOut
bool logToStdOut
is the logger currently writing everything to the standard output
Definition: CamiTKLogger.h:245
camitk::CamiTKLogger::setLogLevel
void setLogLevel(LogLevel level) override
Sets Current verbosity level of the log:
Definition: CamiTKLogger.cpp:96
camitk::CamiTKLogger::getMessageBoxLevel
LogLevel getMessageBoxLevel() override
Definition: CamiTKLogger.cpp:237
camitk::CamiTKLogger::getLogToStandardOutput
bool getLogToStandardOutput() override
check if the logger is currently writing on standard output (std::cout)
Definition: CamiTKLogger.cpp:112
camitk::CamiTKLogger::displayDebugInformation
bool displayDebugInformation
display debug information (file/class name, method name and line number)
Definition: CamiTKLogger.h:251
CamiTKAPI.h
camitk::CamiTKLogger::openLogFile
bool openLogFile(bool moveFile=false, QFileInfo fileToMove=QFileInfo())
open the log file,
Definition: CamiTKLogger.cpp:159
InterfaceLogger.h
camitk::CamiTKLogger::setMessageBoxLevel
void setMessageBoxLevel(LogLevel level) override
Set the lowest log level that will open modal message box for messages instead of (silently/undisrupt...
Definition: CamiTKLogger.cpp:229
camitk::CamiTKLogger::getDebugInformation
bool getDebugInformation() override
Definition: CamiTKLogger.cpp:250
camitk::CamiTKLogger::getLogFileInfo
QFileInfo getLogFileInfo() override
Definition: CamiTKLogger.cpp:219
camitk::CamiTKLogger::logFileDirectory
QDir logFileDirectory
Current directory for the log file.
Definition: CamiTKLogger.h:257
camitk::InterfaceLogger::NONE
No message is logged.
Definition: InterfaceLogger.h:60
camitk::InterfaceLogger::ERROR
Only error messages are logged.
Definition: InterfaceLogger.h:61
camitk::CamiTKLogger::getCamiTKAPIInformation
QString getCamiTKAPIInformation(const QObject *sender)
Returns CamiTK API description string if and only if sender derived from CamiTK Action.
Definition: CamiTKLogger.cpp:345
Action.h
camitk::CamiTKLogger::logToFile
bool logToFile
is the logger currently writing everything to a file
Definition: CamiTKLogger.h:248
ActionExtension.h
Log.h
camitk::CamiTKLogger::buildLogMessage
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.
Definition: CamiTKLogger.cpp:323
camitk::CamiTKLogger::getLogLevel
LogLevel getLogLevel() override
Get Current verbosity level of the log:
Definition: CamiTKLogger.cpp:91
camitk::CamiTKLogger::log
QString log(const QString msg, const LogLevel level, char const *fileName, char const *methodName, int lineNumber, const QObject *sender=nullptr) override
Log a message: If the logger is allowed to write on standard output, it will display the message (and...
Definition: CamiTKLogger.cpp:268
camitk::CamiTKLogger::~CamiTKLogger
~CamiTKLogger() override
Destructor.
Definition: CamiTKLogger.cpp:85
camitk::CamiTKLogger::level
InterfaceLogger::LogLevel level
current log level
Definition: CamiTKLogger.h:239
camitk::CamiTKLogger::messageBoxLevel
InterfaceLogger::LogLevel messageBoxLevel
current level for message boxes
Definition: CamiTKLogger.h:242
camitk::CamiTKLogger::setLogToStandardOutput
void setLogToStandardOutput(bool writeToStdOut) override
Allows the logger to write on std::cout.
Definition: CamiTKLogger.cpp:104
ComponentExtension.h
camitk::CamiTKLogger::logStream
QTextStream * logStream
Current stream to output to the log file.
Definition: CamiTKLogger.h:263
camitk::InterfaceLogger::INFO
information, warning and error messages are logged
Definition: InterfaceLogger.h:63
camitk::CamiTKLogger::getLogToFile
bool getLogToFile() override
check if the logger is currently writing on a file
Definition: CamiTKLogger.cpp:154
camitk::CamiTKLogger::setTimeStampInformation
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....
Definition: CamiTKLogger.cpp:255
camitk::InterfaceLogger::LogLevel
LogLevel
Definition: InterfaceLogger.h:59
camitk::CamiTKLogger::logStartTime
QDateTime logStartTime
instantiation time
Definition: CamiTKLogger.h:266
CamiTKLogger.h
camitk::CamiTKLogger::displayTimeStampInformation
bool displayTimeStampInformation
display time stamp information (in the form "yyyy-MM-dd HH:mm:ss.zzz")
Definition: CamiTKLogger.h:254
MainWindow.h
camitk::CamiTKLogger::setDebugInformation
void setDebugInformation(bool) override
Allows the logger to add debug information to the log message.
Definition: CamiTKLogger.cpp:242
camitk::InterfaceLogger::WARNING
Only Warning and Error messages are logged.
Definition: InterfaceLogger.h:62
camitk::CamiTKLogger::setLogFileDirectory
bool setLogFileDirectory(QDir directoryName, bool moveExistingLogFile=true) override
Set the specific directory to write to (default is the subdirectory "CamiTK" in the system temporary ...
Definition: CamiTKLogger.cpp:133
camitk::Log::getLevelAsString
static QString getLevelAsString(InterfaceLogger::LogLevel level)
get the enum value as a text
Definition: Log.cpp:80
Viewer.h
camitk::CamiTKLogger::closeLogFile
void closeLogFile()
close the current log file and reset state
Definition: CamiTKLogger.cpp:202
camitk::InterfaceLogger::TRACE
all types of messages are logged
Definition: InterfaceLogger.h:64
camitk::CamiTKLogger::setLogToFile
bool setLogToFile(bool writeToFile) override
Allows the logger to write to the log file.
Definition: CamiTKLogger.cpp:117
camitk::CamiTKLogger::getTimeStampInformation
bool getTimeStampInformation() override
Definition: CamiTKLogger.cpp:263
Application.h
CAMITK_API
#define CAMITK_API
Definition: CamiTKAPI.h:48
camitk
Definition: Action.cpp:36