mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1254 Infrastructure for logging including Messages dock widget
This commit is contained in:
parent
dc886b7e9c
commit
3a98e17163
@ -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 <fcntl.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
249
ApplicationCode/Application/RiaLogging.cpp
Normal file
249
ApplicationCode/Application/RiaLogging.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4668)
|
||||
#include <windows.h>
|
||||
#pragma warning (pop)
|
||||
#else
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#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 << "<no message>" << 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<DWORD>(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<RiaDefaultConsoleLogger*>(sm_logger))
|
||||
{
|
||||
delete sm_logger;
|
||||
}
|
||||
|
||||
// VF_ASSERT(loggerInstance);
|
||||
sm_logger = loggerInstance;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaLogging::deleteLoggerInstance()
|
||||
{
|
||||
delete sm_logger;
|
||||
sm_logger = NULL;
|
||||
}
|
||||
|
89
ApplicationCode/Application/RiaLogging.h
Normal file
89
ApplicationCode/Application/RiaLogging.h
Normal file
@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// 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())
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -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<QMdiSubWindow*> 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<RiuMessagePanel> m_messagePanel;
|
||||
|
||||
RiuResultQwtPlot* m_resultQwtPlot;
|
||||
|
||||
|
213
ApplicationCode/UserInterface/RiuMessagePanel.cpp
Normal file
213
ApplicationCode/UserInterface/RiuMessagePanel.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiuMessagePanel.h"
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QMenu>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
80
ApplicationCode/UserInterface/RiuMessagePanel.h
Normal file
80
ApplicationCode/UserInterface/RiuMessagePanel.h
Normal file
@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QWidget>
|
||||
|
||||
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<QPlainTextEdit> 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<RiuMessagePanel> m_messagePanel;
|
||||
int m_logLevel;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user