summaryrefslogtreecommitdiffstats
path: root/src/debugging/TSLogger.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/debugging/TSLogger.cpp')
-rw-r--r--[-rwxr-xr-x]src/debugging/TSLogger.cpp346
1 files changed, 198 insertions, 148 deletions
diff --git a/src/debugging/TSLogger.cpp b/src/debugging/TSLogger.cpp
index b0f280a..2337fc5 100755..100644
--- a/src/debugging/TSLogger.cpp
+++ b/src/debugging/TSLogger.cpp
@@ -35,7 +35,7 @@
using namespace tschweitzer;
using namespace tschweitzer::debugging;
-TSLogger* TSLogger::_instance = NULL;
+TSLogger*TSLogger::_instance = NULL;
/*!
\class TSLogger
@@ -52,200 +52,250 @@ TSLogger* TSLogger::_instance = NULL;
/*!
\brief Returns the only existing instance of TSLogger. If the instance doesn't exist, it will be created.
*/
-TSLogger* TSLogger::getInstance(int verboseLevel) {
- if ( _instance == NULL )
- _instance = new TSLogger(verboseLevel);
-
- return _instance;
+TSLogger* TSLogger::getInstance(int verboseLevel)
+{
+ if (_instance == NULL)
+ {
+ _instance = new TSLogger(verboseLevel);
+ }
+
+ return _instance;
}
-
/*!
\brief Returns the only existing instance of TSLogger. If the instance doesn't exist, it will be created.
*/
-TSLogger* TSLogger::getInstance() {
+TSLogger* TSLogger::getInstance()
+{
#ifdef _DEBUG
- return TSLogger::getInstance(TQtDebugMsg);
+ return TSLogger::getInstance(TQtDebugMsg);
#else
- return TSLogger::getInstance(TQtWarningMsg);
+ return TSLogger::getInstance(TQtWarningMsg);
#endif
}
-
/*!
\brief Initializes the dialog and sets the path to the log file in the systems temporary directory.
Sets the default verbose level to warning level.
*/
-TSLogger::TSLogger(int verboseLevel) : TQDialog() {
+TSLogger::TSLogger(int verboseLevel) :
+ TQDialog()
+{
_TSLoggerDialogForm = new Ui::TSLoggerDialog();
- _TSLoggerDialogForm->setupUi(this);
+ _TSLoggerDialogForm->setupUi(this);
#ifdef _DEBUG
- _verboseLevel = TQtDebugMsg;
+ _verboseLevel = TQtDebugMsg;
#else
- _verboseLevel = TQtMsgType(verboseLevel);
+ _verboseLevel = TQtMsgType(verboseLevel);
#endif
- _logFileInitState = NOTINITIALZED;
+ _logFileInitState = NOTINITIALZED;
- connect( _TSLoggerDialogForm->openLogFileFolderToolButton, SIGNAL(clicked()), this, SLOT(openLogFileFolder()) );
+ connect(_TSLoggerDialogForm->openLogFileFolderToolButton, SIGNAL(clicked()), this,
+ SLOT(openLogFileFolder()));
- // Make the main application not to wait for the logging window to close.
- setAttribute(TQt::WA_QuitOnClose, false);
+ // Make the main application not to wait for the logging window to close.
+ setAttribute(TQt::WA_QuitOnClose, false);
}
-
/*!
\brief Logs all incoming messages \a msg to the dialogs text edit and to the log file.
Only messages whos \a type have a higher priority than the set verbose level are logged.
*/
-void TSLogger::messageHandler(TQtMsgType type, const char *msg) {
- if ( _instance == NULL )
- _instance = TSLogger::getInstance();
-
-/*
- TQMessageBox messageBox;
- TQString messageBoxText = TQString::fromUtf8( msg );
- messageBox.setText( messageBoxText );
- messageBox.setWindowModality( TQt::ApplicationModal );
- messageBox.exec();
-*/
-
- // Only log messages that have a higher or equal priority than set with the verbose level.
- if ( type < _instance->_verboseLevel )
- return;
-
- // Init log message with prepended date and time.
- TQString message = TQDateTime::currentDateTime().toString();
-
- // Depending on the TQtMsgType prepend a different colored Debug, Warning, Critical or Fatal.
- switch (type) {
- case TQtDebugMsg :
- message += " <span style=\"font-weight:bold; color:black;\">Debug:</span> ";
- break;
- case TQtWarningMsg :
- message += " <span style=\"font-weight:bold; color:gold;\">Warning:</span> ";
- break;
- case TQtCriticalMsg :
- message += "<span style=\"font-weight:bold; color:red;\">Critical:</span> ";
- break;
- case TQtFatalMsg :
- message += " <span style=\"font-weight:bold; color:#D60000;\">Fatal:</span> ";
- // This one is no TQt message type, but can be used to send info messages to the log
- // by calling TSLogger::messageHandler() directly.
- case TSLoggerInfoMsg :
- message += " <span style=\"font-weight:bold; color:darkgray;\">Info:</span> ";
- break;
- }
-
- // Append the to UTF-8 back converted message parameter.
- message += TQString::fromUtf8( msg ) + "<br/>\n";
-
- // Write the message to the log windows text edit.
- _instance->_TSLoggerDialogForm->logTextEdit->append( message );
-
- // Write/append the log message to the log file.
- _instance->writeToLogFile( message );
-
- // In case of a fatal error abort the application.
- if ( type == TQtFatalMsg )
- abort();
+void TSLogger::messageHandler(TQtMsgType type, const char *msg)
+{
+ if (_instance == NULL)
+ {
+ _instance = TSLogger::getInstance();
+ }
+
+ /*
+ TQMessageBox messageBox;
+ TQString messageBoxText = TQString::fromUtf8( msg );
+ messageBox.setText( messageBoxText );
+ messageBox.setWindowModality( TQt::ApplicationModal );
+ messageBox.exec();
+ */
+
+ // Only log messages that have a higher or equal priority than set with the verbose level.
+ if (type < _instance->_verboseLevel)
+ {
+ return;
+ }
+
+ // Init log message with prepended date and time.
+ TQString message = TQDateTime::currentDateTime().toString();
+
+ // Depending on the TQtMsgType prepend a different colored Debug, Warning, Critical or Fatal.
+ switch (type)
+ {
+ case TQtDebugMsg:
+ {
+ message += " <span style=\"font-weight:bold; color:black;\">Debug:</span> ";
+ break;
+ }
+
+ case TQtWarningMsg:
+ {
+ message += " <span style=\"font-weight:bold; color:gold;\">Warning:</span> ";
+ break;
+ }
+
+ case TQtCriticalMsg:
+ {
+ message += "<span style=\"font-weight:bold; color:red;\">Critical:</span> ";
+ break;
+ }
+
+ case TQtFatalMsg:
+ {
+ message += " <span style=\"font-weight:bold; color:#D60000;\">Fatal:</span> ";
+ }
+
+ // This one is no TQt message type, but can be used to send info messages to the log
+ // by calling TSLogger::messageHandler() directly.
+ case TSLoggerInfoMsg:
+ {
+ message += " <span style=\"font-weight:bold; color:darkgray;\">Info:</span> ";
+ break;
+ }
+ }
+
+ // Append the to UTF-8 back converted message parameter.
+ message += TQString::fromUtf8(msg) + "<br/>\n";
+
+ // Write the message to the log windows text edit.
+ _instance->_TSLoggerDialogForm->logTextEdit->append(message);
+
+ // Write/append the log message to the log file.
+ _instance->writeToLogFile(message);
+
+ // In case of a fatal error abort the application.
+ if (type == TQtFatalMsg)
+ {
+ abort();
+ }
}
-
/*!
\brief Calling this the verbose level can be set in a range from 0 to 3
which is equal to debug, warning, critical and fatal priority.
*/
-void TSLogger::setVerboseLevel(int level) {
- if ( level < 0 )
- _verboseLevel = TQtDebugMsg;
- if ( level > 3 )
- _verboseLevel = TQtFatalMsg;
- else
- _verboseLevel = TQtMsgType(level);
+void TSLogger::setVerboseLevel(int level)
+{
+ if (level < 0)
+ {
+ _verboseLevel = TQtDebugMsg;
+ }
+ if (level > 3)
+ {
+ _verboseLevel = TQtFatalMsg;
+ }
+ else
+ {
+ _verboseLevel = TQtMsgType(level);
+ }
}
-
/*!
\brief Deletes the existing _instance of TSLogger.
*/
-void TSLogger::deleteInstance() {
- if ( _instance != NULL ) {
- delete _instance;
- _instance = NULL;
- }
+void TSLogger::deleteInstance()
+{
+ if (_instance != NULL)
+ {
+ delete _instance;
+ _instance = NULL;
+ }
}
-
/*!
\brief Opens the folder that contains the created log file with the name "UiGUI_log.html".
*/
-void TSLogger::openLogFileFolder() {
- TQDesktopServices::openUrl( TQFileInfo( _logFile ).absolutePath() );
+void TSLogger::openLogFileFolder()
+{
+ TQDesktopServices::openUrl(TQFileInfo(_logFile).absolutePath());
}
-
/*!
\brief Writes the \a message to the used log file.
*/
-void TSLogger::writeToLogFile(const TQString &message) {
- // If the file where all logging messages should go to isn't initilized yet, do that now.
- if ( _logFileInitState == NOTINITIALZED ) {
- _logFileInitState = INITIALIZING;
-
- // On different systems it may be that "TQDir::tempPath()" ends with a "/" or not. So check this.
- // Remove any trailing slashes.
- TQString tempPath = TQFileInfo( SettingsPaths::getTempPath() ).absolutePath();
- while ( tempPath.right(1) == "/" ) {
- tempPath.chop(1);
- }
-
- // To make the temporary log file invulnerable against file symbolic link hacks
- // append the current date and time up to milliseconds to its name and a random character.
- TQString logFileName = "UiGUI_log_" + TQDateTime::currentDateTime().toString("yyyyMMdd");
- logFileName += "-" + TQDateTime::currentDateTime().toString("hhmmsszzz");
- // By random decide whether to append a number or an upper or lower case character.
- qsrand( time(NULL) );
- unsigned char randomChar;
- switch ( qrand() % 3 ) {
- // Append a number from 0 to 9.
- case 0 :
- randomChar = qrand() % 10 + '0';
- break;
- // Append a upper case characer between A and Z.
- case 1 :
- randomChar = qrand() % 26 + 'A';
- break;
- // Append a lower case characer between a and z.
- default :
- randomChar = qrand() % 26 + 'a';
- break;
- }
- logFileName += "_" + TQString(randomChar) + ".html";
-
- _logFile.setFileName( tempPath + "/" + logFileName );
-
- // Set the tooltip of the open log file folder button to show the unique name of the log file.
- _TSLoggerDialogForm->openLogFileFolderToolButton->setToolTip( _TSLoggerDialogForm->openLogFileFolderToolButton->toolTip() + " (" + logFileName + ")" );
-
- _logFileInitState = INITIALZED;
- }
-
- // Add the message to the message queue.
- _messageQueue << message;
-
- // If the logging file is initialzed, write all messages contained in the message queue into the file.
- if ( _logFileInitState == INITIALZED ) {
- // Write/append the log message to the log file.
- if ( _logFile.open(TQIODevice::WriteOnly | TQIODevice::Text | TQIODevice::Append) ) {
- TQTextStream out(&_logFile);
-
- while ( !_messageQueue.isEmpty() ) {
- out << _messageQueue.takeFirst() << "\n";
- }
-
- _logFile.close();
- }
- }
+void TSLogger::writeToLogFile(const TQString &message)
+{
+ // If the file where all logging messages should go to isn't initilized yet, do that now.
+ if (_logFileInitState == NOTINITIALZED)
+ {
+ _logFileInitState = INITIALIZING;
+
+ // On different systems it may be that "TQDir::tempPath()" ends with a "/" or not. So check
+ // this.
+ // Remove any trailing slashes.
+ TQString tempPath = TQFileInfo(SettingsPaths::getTempPath()).absolutePath();
+ while (tempPath.right(1) == "/")
+ {
+ tempPath.chop(1);
+ }
+
+ // To make the temporary log file invulnerable against file symbolic link hacks
+ // append the current date and time up to milliseconds to its name and a random character.
+ TQString logFileName = "UiGUI_log_" + TQDateTime::currentDateTime().toString("yyyyMMdd");
+ logFileName += "-" + TQDateTime::currentDateTime().toString("hhmmsszzz");
+ // By random decide whether to append a number or an upper or lower case character.
+ qsrand(time(NULL));
+ unsigned char randomChar;
+ switch (qrand() % 3)
+ {
+ // Append a number from 0 to 9.
+ case 0:
+ {
+ randomChar = qrand() % 10 + '0';
+ break;
+ }
+
+ // Append a upper case characer between A and Z.
+ case 1:
+ {
+ randomChar = qrand() % 26 + 'A';
+ break;
+ }
+
+ // Append a lower case characer between a and z.
+ default:
+ {
+ randomChar = qrand() % 26 + 'a';
+ break;
+ }
+ }
+ logFileName += "_" + TQString(randomChar) + ".html";
+
+ _logFile.setFileName(tempPath + "/" + logFileName);
+
+ // Set the tooltip of the open log file folder button to show the unique name of the log file.
+ _TSLoggerDialogForm->openLogFileFolderToolButton->setToolTip(
+ _TSLoggerDialogForm->openLogFileFolderToolButton->toolTip() + " (" + logFileName + ")");
+
+ _logFileInitState = INITIALZED;
+ }
+
+ // Add the message to the message queue.
+ _messageQueue << message;
+
+ // If the logging file is initialzed, write all messages contained in the message queue into the
+ // file.
+ if (_logFileInitState == INITIALZED)
+ {
+ // Write/append the log message to the log file.
+ if (_logFile.open(TQIODevice::WriteOnly | TQIODevice::Text | TQIODevice::Append))
+ {
+ TQTextStream out(&_logFile);
+
+ while (!_messageQueue.isEmpty())
+ {
+ out << _messageQueue.takeFirst() << "\n";
+ }
+
+ _logFile.close();
+ }
+ }
}