diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 2f01a6911f..501cc201c7 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -23,6 +23,7 @@ #include "RiaBaseDefs.h" #include "RiaImageCompareReporter.h" #include "RiaImageFileCompare.h" +#include "RiaLogging.h" #include "RiaPreferences.h" #include "RiaProjectModifier.h" #include "RiaSocketServer.h" @@ -117,6 +118,7 @@ #include #endif + namespace caf { template<> @@ -335,10 +337,16 @@ bool RiaApplication::loadProject(const QString& projectFileName, ProjectLoadActi closeProject(); + RI_LOG_INFO_QSTR(QString("Starting to open project file : '%1'").arg(projectFileName)); + // Open the project file and read the serialized data. // Will initialize itself. - if (!QFile::exists(projectFileName)) return false; + if (!QFile::exists(projectFileName)) + { + RI_LOG_ERROR_QSTR(QString("File does not exist : '%1'").arg(projectFileName)); + return false; + } m_project->fileName = projectFileName; m_project->readFile(); @@ -539,6 +547,8 @@ bool RiaApplication::loadProject(const QString& projectFileName, ProjectLoadActi // Execute command objects, and release the mutex when the queue is empty executeCommandObjects(); + RI_LOG_INFO_QSTR(QString("Completed open of project file : '%1'").arg(projectFileName)); + return true; } diff --git a/ApplicationCode/Application/RiaLogging.cpp b/ApplicationCode/Application/RiaLogging.cpp new file mode 100644 index 0000000000..0f1be24e30 --- /dev/null +++ b/ApplicationCode/Application/RiaLogging.cpp @@ -0,0 +1,249 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017 Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RiaLogging.h" + +#include + +#ifdef WIN32 +#pragma warning (push) +#pragma warning (disable: 4668) +#include +#pragma warning (pop) +#else +#include +#include +#endif + + + + +//================================================================================================== +// +// +// +//================================================================================================== +class RiaDefaultConsoleLogger : public RiaLogger +{ +public: + RiaDefaultConsoleLogger(); + + virtual int level() const; + virtual void setLevel(int logLevel); + virtual void error( const char* message, const char* fileName, int lineNumber); + virtual void warning(const char* message, const char* fileName, int lineNumber); + virtual void info( const char* message, const char* fileName, int lineNumber); + virtual void debug( const char* message, const char* fileName, int lineNumber); + +private: + static void writeMessageToConsole(const char* prefix, const char* message, const char* fileName, int lineNumber); + static void writeToConsole(const std::string& str); + +private: + int m_logLevel; +}; + + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaDefaultConsoleLogger::RiaDefaultConsoleLogger() + : m_logLevel(RI_LL_WARNING) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RiaDefaultConsoleLogger::level() const +{ + return m_logLevel; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaDefaultConsoleLogger::setLevel(int logLevel) +{ + m_logLevel = logLevel; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaDefaultConsoleLogger::error(const char* message, const char* fileName, int lineNumber) +{ + writeMessageToConsole("ERROR: ", message, fileName, lineNumber); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaDefaultConsoleLogger::warning(const char* message, const char*, int) +{ + writeMessageToConsole("warn: ", message, NULL, 0); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaDefaultConsoleLogger::info(const char* message, const char*, int) +{ + writeMessageToConsole("info: ", message, NULL, 0); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaDefaultConsoleLogger::debug(const char* message, const char*, int) +{ + writeMessageToConsole("debug: ", message, NULL, 0); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaDefaultConsoleLogger::writeMessageToConsole(const char* prefix, const char* message, const char* fileName, int lineNumber) +{ + std::ostringstream oss; + +// VF_ASSERT(prefix); + oss << prefix; + + if (message) + { + oss << message << std::endl; + } + else + { + oss << "" << std::endl; + } + + if (fileName) + { + oss << " -file " << RiaLogger::shortFileName(fileName) << ", line " << lineNumber << std::endl; + } + + writeToConsole(oss.str()); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaDefaultConsoleLogger::writeToConsole(const std::string& str) +{ +#ifdef WIN32 + AllocConsole(); + HANDLE hStdOutputHandle = GetStdHandle(STD_OUTPUT_HANDLE); + if (hStdOutputHandle) + { + DWORD stringLength = static_cast(str.length()); + + unsigned long iDum = 0; + WriteConsoleA(hStdOutputHandle, str.c_str(), stringLength, &iDum, NULL); + } +#else + fputs(str.c_str(), stderr); +#endif +} + + +//================================================================================================== +// +// +// +//================================================================================================== + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const char* RiaLogger::shortFileName(const char* fileName) +{ +// VF_ASSERT(fileName); + + const char* ptrToLastSlash = strrchr(fileName, '/'); + +#ifdef WIN32 + const char* ptrToLastBwdSlash = strrchr(fileName, '\\'); + if (ptrToLastBwdSlash > ptrToLastSlash) + { + ptrToLastSlash = ptrToLastBwdSlash; + } +#endif + + if (ptrToLastSlash) + { + return ptrToLastSlash + 1; + } + else + { + return fileName; + } +} + + + + + +//================================================================================================== +// +// +// +//================================================================================================== + +RiaLogger* RiaLogging::sm_logger = new RiaDefaultConsoleLogger; + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaLogger* RiaLogging::loggerInstance() +{ + return sm_logger; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaLogging::setLoggerInstance(RiaLogger* loggerInstance) +{ + // Only delete if we're currently using our own default impl + if (dynamic_cast(sm_logger)) + { + delete sm_logger; + } + +// VF_ASSERT(loggerInstance); + sm_logger = loggerInstance; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaLogging::deleteLoggerInstance() +{ + delete sm_logger; + sm_logger = NULL; +} + diff --git a/ApplicationCode/Application/RiaLogging.h b/ApplicationCode/Application/RiaLogging.h new file mode 100644 index 0000000000..587f590020 --- /dev/null +++ b/ApplicationCode/Application/RiaLogging.h @@ -0,0 +1,89 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017 Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + + +enum RILogLevel +{ + RI_LL_ERROR = 1, + RI_LL_WARNING = 2, + RI_LL_INFO = 3, + RI_LL_DEBUG = 4 +}; + + + +//================================================================================================== +// +// Logger interface for the application +// +//================================================================================================== +class RiaLogger +{ +public: + virtual ~RiaLogger() {} + + virtual int level() const = 0; + virtual void setLevel(int logLevel) = 0; + + virtual void error( const char* message, const char* fileName, int lineNumber) = 0; + virtual void warning(const char* message, const char* fileName, int lineNumber) = 0; + virtual void info( const char* message, const char* fileName, int lineNumber) = 0; + virtual void debug( const char* message, const char* fileName, int lineNumber) = 0; + +protected: + static const char* shortFileName(const char* fileName); +}; + + + +//================================================================================================== +// +// +// +//================================================================================================== +class RiaLogging +{ +public: + static RiaLogger* loggerInstance(); + static void setLoggerInstance(RiaLogger* loggerInstance); + static void deleteLoggerInstance(); + +private: + static RiaLogger* sm_logger; +}; + + + + + +// Helper macros for writing log messages +#define RI_LOG_ERROR_2(theLogger, theMessage) if ((theLogger)->level() >= RI_LL_ERROR) { (theLogger)->error((theMessage), __FILE__, __LINE__); } +#define RI_LOG_WARNING_2(theLogger, theMessage) if ((theLogger)->level() >= RI_LL_WARNING) { (theLogger)->warning((theMessage), __FILE__, __LINE__); } +#define RI_LOG_INFO_2(theLogger, theMessage) if ((theLogger)->level() >= RI_LL_INFO) { (theLogger)->info((theMessage), __FILE__, __LINE__); } +#define RI_LOG_DEBUG_2(theLogger, theMessage) if ((theLogger)->level() >= RI_LL_DEBUG) { (theLogger)->debug((theMessage), __FILE__, __LINE__); } + +#define RI_LOG_ERROR(theMessage) RI_LOG_ERROR_2( RiaLogging::loggerInstance(), theMessage) +#define RI_LOG_ERROR_QSTR(theMessage) RI_LOG_ERROR_2( RiaLogging::loggerInstance(), (theMessage).toLatin1().constData()) +#define RI_LOG_WARNING(theMessage) RI_LOG_WARNING_2( RiaLogging::loggerInstance(), theMessage) +#define RI_LOG_WARNING_QSTR(theMessage) RI_LOG_WARNING_2( RiaLogging::loggerInstance(), (theMessage).toLatin1().constData()) +#define RI_LOG_INFO(theMessage) RI_LOG_INFO_2( RiaLogging::loggerInstance(), theMessage) +#define RI_LOG_INFO_QSTR(theMessage) RI_LOG_INFO_2( RiaLogging::loggerInstance(), (theMessage).toLatin1().constData()) +#define RI_LOG_DEBUG(theMessage) RI_LOG_DEBUG_2( RiaLogging::loggerInstance(), theMessage) +#define RI_LOG_DEBUG_QSTR(theMessage) RI_LOG_DEBUG_2( RiaLogging::loggerInstance(), (theMessage).toLatin1().constData()) diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index 9fcff02517..f7cdbed500 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -80,6 +80,8 @@ set( APPLICATION_FILES Application/RiaProjectModifier.cpp Application/RiaRegressionTest.cpp Application/RiaColorTables.cpp + Application/RiaLogging.h + Application/RiaLogging.cpp ) set( SOCKET_INTERFACE_FILES diff --git a/ApplicationCode/RiaMain.cpp b/ApplicationCode/RiaMain.cpp index d14d0dd18a..b694888f39 100644 --- a/ApplicationCode/RiaMain.cpp +++ b/ApplicationCode/RiaMain.cpp @@ -17,10 +17,15 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RiaApplication.h" +#include "RiaLogging.h" + #include "RiuMainWindow.h" +#include "RiuMessagePanel.h" int main(int argc, char *argv[]) { + RiaLogging::loggerInstance()->setLevel(RI_LL_DEBUG); + RiaApplication app(argc, argv); QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); @@ -39,11 +44,19 @@ int main(int argc, char *argv[]) window.loadWinGeoAndDockToolBarLayout(); window.showWindow(); + RiaLogging::setLoggerInstance(new RiuMessagePanelLogger(window.messagePanel())); + RiaLogging::loggerInstance()->setLevel(RI_LL_DEBUG); + if (app.parseArguments()) { - return app.exec(); + int exitCode = app.exec(); + RiaLogging::deleteLoggerInstance(); + + return exitCode; } + RiaLogging::deleteLoggerInstance(); + return 0; } diff --git a/ApplicationCode/UserInterface/CMakeLists_files.cmake b/ApplicationCode/UserInterface/CMakeLists_files.cmake index cac5da412e..1579fb480b 100644 --- a/ApplicationCode/UserInterface/CMakeLists_files.cmake +++ b/ApplicationCode/UserInterface/CMakeLists_files.cmake @@ -40,6 +40,7 @@ ${CEE_CURRENT_LIST_DIR}RiuFemTimeHistoryResultAccessor.h ${CEE_CURRENT_LIST_DIR}RiuExportMultipleSnapshotsWidget.h ${CEE_CURRENT_LIST_DIR}RiuWellAllocationPlot.h ${CEE_CURRENT_LIST_DIR}RiuNightchartsWidget.h +${CEE_CURRENT_LIST_DIR}RiuMessagePanel.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -78,6 +79,7 @@ ${CEE_CURRENT_LIST_DIR}RiuFemTimeHistoryResultAccessor.cpp ${CEE_CURRENT_LIST_DIR}RiuExportMultipleSnapshotsWidget.cpp ${CEE_CURRENT_LIST_DIR}RiuWellAllocationPlot.cpp ${CEE_CURRENT_LIST_DIR}RiuNightchartsWidget.cpp +${CEE_CURRENT_LIST_DIR}RiuMessagePanel.cpp ) list(APPEND CODE_HEADER_FILES @@ -106,6 +108,7 @@ ${CEE_CURRENT_LIST_DIR}RiuQwtScalePicker.h ${CEE_CURRENT_LIST_DIR}RiuExportMultipleSnapshotsWidget.h ${CEE_CURRENT_LIST_DIR}RiuWellAllocationPlot.h ${CEE_CURRENT_LIST_DIR}RiuNightchartsWidget.h +${CEE_CURRENT_LIST_DIR}RiuMessagePanel.h ) list(APPEND QT_UI_FILES diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index e1fd6d00e9..2489a85966 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -38,6 +38,7 @@ #include "RiuDragDrop.h" #include "RiuMdiSubWindow.h" +#include "RiuMessagePanel.h" #include "RiuProcessMonitor.h" #include "RiuProjectPropertyView.h" #include "RiuPropertyViewTabWidget.h" @@ -587,6 +588,15 @@ void RiuMainWindow::createDockPanels() addDockWidget(Qt::BottomDockWidgetArea, dockPanel); } + { + QDockWidget* dockWidget = new QDockWidget("Messages", this); + dockWidget->setObjectName("dockMessages"); + m_messagePanel = new RiuMessagePanel(dockWidget); + dockWidget->setWidget(m_messagePanel); + addDockWidget(Qt::BottomDockWidgetArea, dockWidget); + dockWidget->hide(); + } + setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea); } @@ -801,6 +811,14 @@ RiuResultQwtPlot* RiuMainWindow::resultPlot() return m_resultQwtPlot; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuMessagePanel* RiuMainWindow::messagePanel() +{ + return m_messagePanel; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuMainWindow.h b/ApplicationCode/UserInterface/RiuMainWindow.h index 11b90ff4e6..7b113b4ce2 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.h +++ b/ApplicationCode/UserInterface/RiuMainWindow.h @@ -37,17 +37,20 @@ class QSpinBox; class QUndoView; class RimCase; + +class RiuMessagePanel; class RiuProcessMonitor; class RiuResultInfoPanel; -class RiuViewer; class RiuResultQwtPlot; +class RiuViewer; + struct RimMdiWindowGeometry; namespace caf { class PdmUiTreeView; class AnimationToolBar; - class PdmObject; + class PdmObject; class PdmUiPropertyView; class PdmUiItem; } @@ -109,7 +112,8 @@ public: QMdiSubWindow* findMdiSubWindow(QWidget* viewer); QList subWindowList(QMdiArea::WindowOrder order); - RiuResultQwtPlot* resultPlot(); + RiuResultQwtPlot* resultPlot(); + RiuMessagePanel* messagePanel(); protected: virtual void closeEvent(QCloseEvent* event); @@ -158,6 +162,7 @@ private: RiuViewer* m_mainViewer; RiuResultInfoPanel* m_resultInfoPanel; RiuProcessMonitor* m_processMonitor; + QPointer m_messagePanel; RiuResultQwtPlot* m_resultQwtPlot; diff --git a/ApplicationCode/UserInterface/RiuMessagePanel.cpp b/ApplicationCode/UserInterface/RiuMessagePanel.cpp new file mode 100644 index 0000000000..857cd40140 --- /dev/null +++ b/ApplicationCode/UserInterface/RiuMessagePanel.cpp @@ -0,0 +1,213 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017- Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RiuMessagePanel.h" + +#include +#include +#include +#include + + + +//================================================================================================== +// +// +// +//================================================================================================== + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuMessagePanel::RiuMessagePanel(QDockWidget* parent) +: QWidget(parent) +{ + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setMargin(0); + + m_textEdit = new QPlainTextEdit; + m_textEdit->setReadOnly(true); + m_textEdit->setLineWrapMode(QPlainTextEdit::NoWrap); + m_textEdit->setContextMenuPolicy(Qt::CustomContextMenu); + + connect(m_textEdit, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(slotShowContextMenu(const QPoint&))); + + layout->addWidget(m_textEdit); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMessagePanel::addMessage(RILogLevel messageLevel, const QString& msg, const QString& srcInfo) +{ + QColor clr(Qt::black); + if (messageLevel == RI_LL_ERROR) clr = Qt::red; + else if (messageLevel == RI_LL_WARNING) clr = QColor(220,100,10); + else if (messageLevel == RI_LL_DEBUG) clr = QColor(100,100,200); + + QTextCharFormat form = m_textEdit->currentCharFormat(); + form.setForeground(clr); + form.setFontWeight(messageLevel == RI_LL_ERROR ? QFont::DemiBold : QFont::Normal); + form.setFontItalic(messageLevel == RI_LL_DEBUG ? true : false); + m_textEdit->setCurrentCharFormat(form); + m_textEdit->appendPlainText(msg); + + if (!srcInfo.isEmpty()) + { + form.setForeground(clr); + form.setFontWeight(QFont::Normal); + form.setFontItalic(true); + m_textEdit->setCurrentCharFormat(form); + m_textEdit->appendPlainText(" " + srcInfo); + } + + m_textEdit->moveCursor(QTextCursor::End); + m_textEdit->ensureCursorVisible(); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QSize RiuMessagePanel::sizeHint() const +{ + return QSize(20, 20); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMessagePanel::slotShowContextMenu(const QPoint& pos) +{ + QMenu* menu = m_textEdit->createStandardContextMenu(); + + menu->addSeparator(); + menu->addAction("Clear All &Messages", this, SLOT(slotClearMessages())); + + menu->exec(m_textEdit->mapToGlobal(pos)); + + delete menu; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMessagePanel::slotClearMessages() +{ + m_textEdit->clear(); + RI_LOG_INFO("Message window cleared."); +} + + + +//================================================================================================== +// +// +// +//================================================================================================== + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuMessagePanelLogger::RiuMessagePanelLogger(RiuMessagePanel* messagePanel) +: m_messagePanel(messagePanel), + m_logLevel(RI_LL_WARNING) +{ +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RiuMessagePanelLogger::level() const +{ + return m_logLevel; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMessagePanelLogger::setLevel(int logLevel) +{ + m_logLevel = logLevel; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMessagePanelLogger::error(const char* message, const char* fileName, int lineNumber) +{ + writeToMessagePanel(RI_LL_ERROR, message, fileName, lineNumber); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMessagePanelLogger::warning(const char* message, const char* fileName, int lineNumber) +{ + writeToMessagePanel(RI_LL_WARNING, message, fileName, lineNumber); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMessagePanelLogger::info(const char* message, const char* fileName, int lineNumber) +{ + writeToMessagePanel(RI_LL_INFO, message, fileName, lineNumber); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMessagePanelLogger::debug(const char* message, const char* fileName, int lineNumber) +{ + writeToMessagePanel(RI_LL_DEBUG, message, fileName, lineNumber); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMessagePanelLogger::writeToMessagePanel(RILogLevel messageLevel, const char* message, const char* fileName, int lineNumber) +{ + if (messageLevel > m_logLevel) + { + return; + } + + if (m_messagePanel) + { + QString codeLocation; + if (messageLevel == RI_LL_ERROR) + { + codeLocation = QString("(file %1, line %2)").arg(RiaLogger::shortFileName(fileName)).arg(lineNumber); + } + + m_messagePanel->addMessage(messageLevel, message, codeLocation); + } +} + + diff --git a/ApplicationCode/UserInterface/RiuMessagePanel.h b/ApplicationCode/UserInterface/RiuMessagePanel.h new file mode 100644 index 0000000000..79644e4bfc --- /dev/null +++ b/ApplicationCode/UserInterface/RiuMessagePanel.h @@ -0,0 +1,80 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017- Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RiaLogging.h" + +#include +#include + +class QDockWidget; +class QPlainTextEdit; + + +//================================================================================================== +// +// +// +//================================================================================================== +class RiuMessagePanel : public QWidget +{ + Q_OBJECT + +public: + RiuMessagePanel(QDockWidget* parent); + + void addMessage(RILogLevel messageLevel, const QString& msg, const QString& srcInfo); + virtual QSize sizeHint () const; + +private slots: + void slotShowContextMenu(const QPoint& pos); + void slotClearMessages(); + +private: + QPointer m_textEdit; +}; + + + +//================================================================================================== +// +// +// +//================================================================================================== +class RiuMessagePanelLogger : public RiaLogger +{ +public: + RiuMessagePanelLogger(RiuMessagePanel* messagePanel); + + virtual int level() const override; + virtual void setLevel(int logLevel) override; + + virtual void error( const char* message, const char* fileName, int lineNumber) override; + virtual void warning(const char* message, const char* fileName, int lineNumber) override; + virtual void info( const char* message, const char* fileName, int lineNumber) override; + virtual void debug( const char* message, const char* fileName, int lineNumber) override; + +private: + void writeToMessagePanel(RILogLevel messageLevel, const char* message, const char* fileName, int lineNumber); + +private: + QPointer m_messagePanel; + int m_logLevel; +}; +