-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
refactor: Log level documentation on SolverBase and children (#3230)
Co-authored-by: MelReyCG <melvin.rey@capgemini.com> Co-authored-by: Pavel Tomin <paveltomin@users.noreply.github.com>
1 parent
e601fad
commit 5a97808
Showing
53 changed files
with
1,634 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* ------------------------------------------------------------------------------------------------------------ | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
* | ||
* Copyright (c) 2018-2020 Lawrence Livermore National Security LLC | ||
* Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University | ||
* Copyright (c) 2018-2020 TotalEnergies | ||
* Copyright (c) 2019- GEOSX Contributors | ||
* All rights reserved | ||
* | ||
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. | ||
* ------------------------------------------------------------------------------------------------------------ | ||
*/ | ||
|
||
/** | ||
* @file LogLevelsInfo.hpp | ||
* This file contains log level information infrastructure and the mecanism to ensure LOG_LEVEL_INFO structure is valid | ||
*/ | ||
#ifndef GEOS_COMMON_LOGLEVELSINFO_HPP | ||
#define GEOS_COMMON_LOGLEVELSINFO_HPP | ||
|
||
#include "common/DataTypes.hpp" | ||
#include "common/format/Format.hpp" | ||
|
||
namespace geos | ||
{ | ||
|
||
/** | ||
* @brief Trait used to check whether a LOG_LEVEL_INFO structure is valid. | ||
* @tparam LOG_LEVEL_INFO The log level structure to check. | ||
* | ||
* A log level structure must have this following | ||
* struct LogName | ||
* { | ||
* static constexpr int getMinLogLevel() { return 1; } | ||
* static constexpr std::string_view getDescription() { return "Log level description"; } | ||
* }; | ||
*/ | ||
template< typename LOG_LEVEL_INFO > | ||
static constexpr bool is_log_level_info = | ||
std::is_same_v< integer, decltype(LOG_LEVEL_INFO::getMinLogLevel()) > && | ||
std::is_same_v< std::string_view, decltype(LOG_LEVEL_INFO::getDescription()) >; | ||
|
||
/** | ||
* @brief Verify if a log level is active | ||
* @tparam LOG_LEVEL_INFO The structure containing log level information. | ||
* @param level Log level to be checked. | ||
* @return `true` if the log level is active, `false` otherwise. | ||
* @pre `LOG_LEVEL_INFO` must satisfy `logInfo::is_log_level_info`. | ||
* | ||
*/ | ||
template< typename LOG_LEVEL_INFO > | ||
std::enable_if_t< is_log_level_info< LOG_LEVEL_INFO >, bool > | ||
isLogLevelActive( integer level ) | ||
{ | ||
return level >= LOG_LEVEL_INFO::getMinLogLevel(); | ||
} | ||
|
||
/** ThOSE 3 macros would replace the ones in Logger.hpp */ | ||
/** | ||
* @brief Output messages based on current Group's log level. | ||
* @param[in] logInfoStruct Strut containing log level desscription | ||
* @param[in] msg a message to log (any expression that can be stream inserted) | ||
*/ | ||
#define GEOS_LOG_LEVEL_INFO( logInfoStruct, msg ) GEOS_LOG_IF( isLogLevelActive< logInfoStruct >( this->getLogLevel() ), msg ); | ||
|
||
/** | ||
* @brief Output messages (only on rank 0) based on current Group's log level. | ||
* @param[in] logInfoStruct Strut containing log level desscription | ||
* @param[in] msg a message to log (any expression that can be stream inserted) | ||
*/ | ||
#define GEOS_LOG_LEVEL_INFO_RANK_0( logInfoStruct, msg ) GEOS_LOG_RANK_0_IF( isLogLevelActive< logInfoStruct >( this->getLogLevel() ), msg ); | ||
|
||
/** | ||
* @brief Output messages (with one line per rank) based on current Group's log level. | ||
* @param[in] logInfoStruct Strut containing log level desscription | ||
* @param[in] msg a message to log (any expression that can be stream inserted) | ||
*/ | ||
#define GEOS_LOG_LEVEL_INFO_BY_RANK( logInfoStruct, msg ) GEOS_LOG_RANK_IF( isLogLevelActive< logInfoStruct >( this->getLogLevel() ), msg ); | ||
|
||
/** | ||
* @brief Output messages (only on rank 0) based on current Group's log level without the line return. | ||
* @param[in] logInfoStruct Strut containing log level desscription | ||
* @param[in] msg a message to log (any expression that can be stream inserted) | ||
*/ | ||
#define GEOS_LOG_LEVEL_INFO_RANK_0_NLR( logInfoStruct, msg ) GEOS_LOG_RANK_0_IF_NLR( isLogLevelActive< logInfoStruct >( this->getLogLevel() ), msg ); | ||
|
||
} | ||
|
||
#endif // GEOS_COMMON_LOGLEVELSINFO_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* ------------------------------------------------------------------------------------------------------------ | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
* | ||
* Copyright (c) 2018-2020 Lawrence Livermore National Security LLC | ||
* Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University | ||
* Copyright (c) 2018-2020 TotalEnergies | ||
* Copyright (c) 2019- GEOSX Contributors | ||
* All rights reserved | ||
* | ||
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. | ||
* ------------------------------------------------------------------------------------------------------------ | ||
*/ | ||
|
||
#include "LogLevelsRegistry.hpp" | ||
|
||
namespace geos | ||
{ | ||
|
||
void LogLevelsRegistry::addEntry( integer condition, std::string_view description ) | ||
{ | ||
m_logLevelsDescriptions[condition].push_back( string( description ) ); | ||
} | ||
|
||
string LogLevelsRegistry::buildLogLevelDescription() const | ||
{ | ||
std::ostringstream description; | ||
description << "Sets the level of information to write in the standard output (the console typically).\n" | ||
"Level 0 outputs no specific information for this solver. Higher levels require more outputs."; | ||
for( auto const & [logLevel, logDescriptions] : m_logLevelsDescriptions ) | ||
{ | ||
description << GEOS_FMT( "\n{}\n", logLevel ); | ||
for( size_t idxDesc = 0; idxDesc < logDescriptions.size(); idxDesc++ ) | ||
{ | ||
description << " - " << logDescriptions[idxDesc]; | ||
if( idxDesc != logDescriptions.size() - 1 ) | ||
description << '\n'; | ||
} | ||
} | ||
return description.str(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* ------------------------------------------------------------------------------------------------------------ | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
* | ||
* Copyright (c) 2018-2020 Lawrence Livermore National Security LLC | ||
* Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University | ||
* Copyright (c) 2018-2020 TotalEnergies | ||
* Copyright (c) 2019- GEOSX Contributors | ||
* All rights reserved | ||
* | ||
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. | ||
* ------------------------------------------------------------------------------------------------------------ | ||
*/ | ||
|
||
/** | ||
* @file LogLevelsRegistry.hpp | ||
*/ | ||
|
||
#ifndef GEOS_COMMON_LOGLEVELSREGISTRY_HPP | ||
#define GEOS_COMMON_LOGLEVELSREGISTRY_HPP | ||
|
||
#include "common/DataTypes.hpp" | ||
#include "common/format/Format.hpp" | ||
|
||
namespace geos | ||
{ | ||
|
||
/** | ||
* @brief Keep track of log level documention for a group | ||
*/ | ||
class LogLevelsRegistry | ||
{ | ||
public: | ||
|
||
/** | ||
* @brief Add a log description for a wrapper | ||
* @param level The minimum log level | ||
* @param description The description for the log level | ||
*/ | ||
void addEntry( integer level, std::string_view description ); | ||
|
||
/** | ||
* @brief Construct the log level string description for a wrapper | ||
* @return The log level string description | ||
*/ | ||
string buildLogLevelDescription() const; | ||
|
||
private: | ||
|
||
/** | ||
* @brief Map for building the log level string for each wrapper. | ||
* key : a logLevel condition, values : a set of description for a corresponding loglevel. | ||
*/ | ||
std::map< integer, std::vector< std::string > > m_logLevelsDescriptions; | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.