Skip to content

Commit

Permalink
Merge branch 'dev' into sigurdp/vizfwk-qopenglwidget
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdp committed Jan 18, 2024
2 parents c3b2f96 + a48faeb commit a0a4e25
Show file tree
Hide file tree
Showing 47 changed files with 1,744 additions and 304 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
[submodule "ThirdParty/qtadvanceddocking"]
path = ThirdParty/qtadvanceddocking
url = https://github.com/CeetronSolutions/qtadvanceddocking.git
[submodule "ThirdParty/spdlog"]
path = ThirdParty/spdlog
url = https://github.com/gabime/spdlog.git
6 changes: 1 addition & 5 deletions ApplicationExeCode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,7 @@ foreach(riFileName ${RI_FILENAMES})
$<TARGET_FILE_DIR:ResInsightDummyTarget>
)
endforeach()
add_custom_target(
PreBuildFileCopy
COMMENT "PreBuildFileCopy step: copy runtime files into build folder"
${copyCommands}
)
add_custom_target(PreBuildFileCopy ${copyCommands})
set_property(TARGET PreBuildFileCopy PROPERTY FOLDER "FileCopyTargets")

# Make ResInsight depend on the prebuild target.
Expand Down
3 changes: 0 additions & 3 deletions ApplicationExeCode/RiaMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/////////////////////////////////////////////////////////////////////////////////

#include "RiaArgumentParser.h"
#include "RiaLogging.h"
#include "RiaMainTools.h"

#ifdef ENABLE_GRPC
Expand Down Expand Up @@ -72,8 +71,6 @@ int main( int argc, char* argv[] )
return 1;
}
#endif
// Global initialization
RiaLogging::loggerInstance()->setLevel( int( RILogLevel::RI_LL_DEBUG ) );

// Create feature manager before the application object is created
RiaMainTools::initializeSingletons();
Expand Down
5 changes: 3 additions & 2 deletions ApplicationLibCode/Application/RiaConsoleApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ void RiaConsoleApplication::initialize()

RiaApplication::initialize();

RiaLogging::setLoggerInstance( std::make_unique<RiaStdOutLogger>() );
RiaLogging::loggerInstance()->setLevel( int( RiaLogging::logLevelBasedOnPreferences() ) );
auto logger = std::make_unique<RiaStdOutLogger>();
logger->setLevel( int( RiaLogging::logLevelBasedOnPreferences() ) );
RiaLogging::appendLoggerInstance( std::move( logger ) );

m_socketServer = new RiaSocketServer( this );
}
Expand Down
26 changes: 20 additions & 6 deletions ApplicationLibCode/Application/RiaGuiApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "RiaArgumentParser.h"
#include "RiaBaseDefs.h"
#include "RiaDefines.h"
#include "RiaFileLogger.h"
#include "RiaFilePathTools.h"
#include "RiaFontCache.h"
#include "RiaImportEclipseCaseTools.h"
Expand Down Expand Up @@ -432,9 +433,18 @@ void RiaGuiApplication::initialize()
auto logger = std::make_unique<RiuMessagePanelLogger>();
logger->addMessagePanel( m_mainWindow->messagePanel() );
logger->addMessagePanel( m_mainPlotWindow->messagePanel() );
RiaLogging::setLoggerInstance( std::move( logger ) );
logger->setLevel( int( RiaLogging::logLevelBasedOnPreferences() ) );

RiaLogging::loggerInstance()->setLevel( int( RiaLogging::logLevelBasedOnPreferences() ) );
RiaLogging::appendLoggerInstance( std::move( logger ) );

auto filename = RiaPreferences::current()->loggerFilename();
if ( !filename.isEmpty() )
{
auto fileLogger = std::make_unique<RiaFileLogger>( filename.toStdString() );
fileLogger->setLevel( int( RiaLogging::logLevelBasedOnPreferences() ) );

RiaLogging::appendLoggerInstance( std::move( fileLogger ) );
}
}
m_socketServer = new RiaSocketServer( this );
}
Expand Down Expand Up @@ -501,7 +511,7 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
auto stdLogger = std::make_unique<RiaStdOutLogger>();
stdLogger->setLevel( int( RILogLevel::RI_LL_DEBUG ) );

RiaLogging::setLoggerInstance( std::move( stdLogger ) );
RiaLogging::appendLoggerInstance( std::move( stdLogger ) );

RiaRegressionTestRunner::instance()->executeRegressionTests( regressionTestPath, QStringList() );
return ApplicationStatus::EXIT_COMPLETED;
Expand Down Expand Up @@ -964,10 +974,14 @@ void RiaGuiApplication::createMainWindow()
m_mainWindow->showWindow();

// if there is an existing logger, reconnect to it
auto logger = dynamic_cast<RiuMessagePanelLogger*>( RiaLogging::loggerInstance() );
if ( logger )

for ( auto logger : RiaLogging::loggerInstances() )
{
logger->addMessagePanel( m_mainWindow->messagePanel() );
auto messagePanelLogger = dynamic_cast<RiuMessagePanelLogger*>( logger );
if ( messagePanelLogger )
{
messagePanelLogger->addMessagePanel( m_mainWindow->messagePanel() );
}
}
}

Expand Down
39 changes: 39 additions & 0 deletions ApplicationLibCode/Application/RiaPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "cafPdmFieldCvfColor.h"
#include "cafPdmSettings.h"
#include "cafPdmUiCheckBoxAndTextEditor.h"
#include "cafPdmUiCheckBoxEditor.h"
#include "cafPdmUiComboBoxEditor.h"
#include "cafPdmUiFieldHandle.h"
Expand Down Expand Up @@ -125,6 +126,18 @@ RiaPreferences::RiaPreferences()
m_pythonExecutable.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::TOP );
CAF_PDM_InitField( &showPythonDebugInfo, "pythonDebugInfo", false, "Show Python Debug Info" );

auto defaultFilename = QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation );
if ( defaultFilename.isEmpty() )
{
defaultFilename = QStandardPaths::writableLocation( QStandardPaths::HomeLocation );
}
defaultFilename += "/ResInsight.log";

CAF_PDM_InitField( &m_loggerFilename, "loggerFilename", std::make_pair( false, defaultFilename ), "Logging To File" );
m_loggerFilename.uiCapability()->setUiEditorTypeName( caf::PdmUiCheckBoxAndTextEditor::uiEditorTypeName() );

CAF_PDM_InitField( &m_loggerFlushInterval, "loggerFlushInterval", 500, "Logging Flush Interval [ms]" );

CAF_PDM_InitField( &ssihubAddress, "ssihubAddress", QString( "http://" ), "SSIHUB Address" );
ssihubAddress.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::TOP );

Expand Down Expand Up @@ -461,6 +474,11 @@ void RiaPreferences::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
caf::PdmUiGroup* otherGroup = uiOrdering.addNewGroup( "Other" );
otherGroup->add( &m_gridCalculationExpressionFolder );
otherGroup->add( &m_summaryCalculationExpressionFolder );

caf::PdmUiGroup* loggingGroup = uiOrdering.addNewGroup( "Logging" );
loggingGroup->add( &m_loggerFilename );
loggingGroup->add( &m_loggerFlushInterval );
m_loggerFlushInterval.uiCapability()->setUiReadOnly( !m_loggerFilename().first );
}
else if ( RiaApplication::enableDevelopmentFeatures() && uiConfigName == RiaPreferences::tabNameSystem() )
{
Expand Down Expand Up @@ -932,6 +950,27 @@ QString RiaPreferences::octaveExecutable() const
return m_octaveExecutable().trimmed();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaPreferences::loggerFilename() const
{
if ( m_loggerFilename().first )
{
return m_loggerFilename().second;
}

return {};
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaPreferences::loggerFlushInterval() const
{
return m_loggerFlushInterval();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions ApplicationLibCode/Application/RiaPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class RiaPreferences : public caf::PdmObject
QString pythonExecutable() const;
QString octaveExecutable() const;

QString loggerFilename() const;
int loggerFlushInterval() const;

RiaPreferencesGeoMech* geoMechPreferences() const;
RiaPreferencesSummary* summaryPreferences() const;
RiaPreferencesSystem* systemPreferences() const;
Expand Down Expand Up @@ -203,6 +206,10 @@ class RiaPreferences : public caf::PdmObject
caf::PdmField<QString> m_octaveExecutable;
caf::PdmField<QString> m_pythonExecutable;

// Logging
caf::PdmField<std::pair<bool, QString>> m_loggerFilename;
caf::PdmField<int> m_loggerFlushInterval;

// Surface Import
caf::PdmField<double> m_surfaceImportResamplingDistance;

Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/Application/Tools/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaOpenMPTools.h
${CMAKE_CURRENT_LIST_DIR}/RiaNumericalTools.h
${CMAKE_CURRENT_LIST_DIR}/RiaRegressionTextTools.h
${CMAKE_CURRENT_LIST_DIR}/RiaFileLogger.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand Down Expand Up @@ -103,6 +104,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaOpenMPTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaNumericalTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaRegressionTextTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaFileLogger.cpp
)

list(APPEND CODE_SOURCE_FILES ${SOURCE_GROUP_SOURCE_FILES})
Expand Down
152 changes: 152 additions & 0 deletions ApplicationLibCode/Application/Tools/RiaFileLogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024 Equinor 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 "RiaFileLogger.h"
#include "RiaPreferences.h"

#include "spdlog/logger.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/spdlog.h"

class RiaFileLogger::Impl
{
public:
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Impl( const std::string& fileName )
{
try
{
m_spdlogger = spdlog::basic_logger_mt( "basic_logger", fileName );

auto flushInterval = RiaPreferences::current()->loggerFlushInterval();
spdlog::flush_every( std::chrono::milliseconds( flushInterval ) );
}
catch ( ... )
{
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void log( const std::string& message )
{
if ( m_spdlogger ) m_spdlogger->info( message );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void info( const std::string& message )
{
if ( m_spdlogger ) m_spdlogger->info( message );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void debug( const std::string& message )
{
if ( m_spdlogger ) m_spdlogger->debug( message );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void error( const std::string& message )
{
if ( m_spdlogger ) m_spdlogger->error( message );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void warning( const std::string& message )
{
if ( m_spdlogger ) m_spdlogger->warn( message );
}

private:
std::shared_ptr<spdlog::logger> m_spdlogger;
};

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaFileLogger::RiaFileLogger( const std::string& filename )
: m_impl( new Impl( filename ) )
, m_logLevel( int( RILogLevel::RI_LL_DEBUG ) )

{
}

//--------------------------------------------------------------------------------------------------
/// The destructor must be located in the cpp file after the definition of RiaFileLogger::Impl to make sure the Impl class is defined when
/// the destructor of std::unique_ptr<Impl> is called
//--------------------------------------------------------------------------------------------------
RiaFileLogger::~RiaFileLogger() = default;

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaFileLogger::level() const
{
return m_logLevel;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaFileLogger::setLevel( int logLevel )
{
m_logLevel = logLevel;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaFileLogger::error( const char* message )
{
m_impl->error( message );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaFileLogger::warning( const char* message )
{
m_impl->warning( message );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaFileLogger::info( const char* message )
{
m_impl->info( message );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaFileLogger::debug( const char* message )
{
m_impl->debug( message );
}
Loading

0 comments on commit a0a4e25

Please sign in to comment.