diff --git a/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h b/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h new file mode 100644 index 0000000000000000000000000000000000000000..323af967e20e34eed9f5b5a1bceafe73f8b4294c --- /dev/null +++ b/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h @@ -0,0 +1,88 @@ +/** + * \copyright + * Copyright (c) 2012-2014, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +namespace BaseLib { + +#ifdef USE_MPI +template <int T_SUPPPRESS_TOPIC_FLAG> +TemplateLogogFormatterSuppressedGCC<T_SUPPPRESS_TOPIC_FLAG> +::TemplateLogogFormatterSuppressedGCC(MPI_Comm mpi_comm) +{ + int rank = 0; + MPI_Comm_rank(mpi_comm, &rank); + int size = 0; + MPI_Comm_size(mpi_comm, &size); + int digits = size/10 + 1; + _str_mpi_rank = "rank " + padLeft(std::to_string(rank), digits) + "| "; +} +#endif + +template <int T_SUPPPRESS_TOPIC_FLAG> +LOGOG_STRING & +TemplateLogogFormatterSuppressedGCC<T_SUPPPRESS_TOPIC_FLAG> +::Format( const logog::Topic &topic, const logog::Target &target ) +{ + TOPIC_FLAGS flags; + flags = GetTopicFlags( topic ); + + m_sMessageBuffer.clear(); + +#ifdef USE_MPI + m_sMessageBuffer.append(_str_mpi_rank.c_str()); +#endif + + if ( flags & TOPIC_FILE_NAME_FLAG ) + { + m_sMessageBuffer.append( topic.FileName() ); + m_sMessageBuffer.append( ':' ); + } + + if ( flags & TOPIC_LINE_NUMBER_FLAG ) + { + m_sIntBuffer.assign( topic.LineNumber() ); + m_sMessageBuffer.append( m_sIntBuffer ); + + m_sMessageBuffer.append( LOGOG_CONST_STRING(": ")); + } + + RenderTimeOfDay(); + + if ( flags & TOPIC_LEVEL_FLAG ) + { + m_sMessageBuffer.append( ErrorDescription( topic.Level())); + m_sMessageBuffer.append( LOGOG_CONST_STRING(": ")); + } + + if ( flags & TOPIC_GROUP_FLAG ) + { + m_sMessageBuffer.append( LOGOG_CONST_STRING("{") ); + m_sMessageBuffer.append( topic.Group() ); + m_sMessageBuffer.append( LOGOG_CONST_STRING("} ") ); + } + + if ( flags & TOPIC_CATEGORY_FLAG ) + { + m_sMessageBuffer.append( LOGOG_CONST_STRING("[")); + m_sMessageBuffer.append( topic.Category() ); + m_sMessageBuffer.append( LOGOG_CONST_STRING("] ")); + } + + if ( flags & TOPIC_MESSAGE_FLAG ) + { + m_sMessageBuffer.append( topic.Message() ); + m_sMessageBuffer.append( (LOGOG_CHAR)'\n' ); + } + + if ( target.GetNullTerminatesStrings() ) + m_sMessageBuffer.append( (LOGOG_CHAR)NULL ); + + return m_sMessageBuffer; +} + +} // namespace BaseLib diff --git a/BaseLib/TemplateLogogFormatterSuppressedGCC.h b/BaseLib/TemplateLogogFormatterSuppressedGCC.h index e52877c864781ca31b26445f6a1e634e0f2d25a1..f65cb4807ee14b03781b47fa38934135f8f96a80 100644 --- a/BaseLib/TemplateLogogFormatterSuppressedGCC.h +++ b/BaseLib/TemplateLogogFormatterSuppressedGCC.h @@ -15,8 +15,14 @@ #ifndef TEMPLATELOGOGFORMATTERSUPPRESSEDGCC_H_ #define TEMPLATELOGOGFORMATTERSUPPRESSEDGCC_H_ -// ** INCLUDES ** +#include <string> + #include "logog/include/logog.hpp" +#ifdef USE_MPI +#include <mpi.h> +#endif + +#include "StringTools.h" namespace BaseLib { @@ -28,6 +34,10 @@ namespace BaseLib { template <int T_SUPPPRESS_TOPIC_FLAG> class TemplateLogogFormatterSuppressedGCC : public logog::FormatterGCC { +public: +#ifdef USE_MPI + TemplateLogogFormatterSuppressedGCC(MPI_Comm mpi_comm = MPI_COMM_WORLD); +#endif virtual TOPIC_FLAGS GetTopicFlags( const logog::Topic &topic ) { @@ -35,8 +45,16 @@ class TemplateLogogFormatterSuppressedGCC : public logog::FormatterGCC ~( T_SUPPPRESS_TOPIC_FLAG )); } -}; + virtual LOGOG_STRING &Format( const logog::Topic &topic, const logog::Target &target ); -#endif // TEMPLATELOGOGFORMATTERSUPPRESSEDGCC_H_ +private: +#ifdef USE_MPI + std::string _str_mpi_rank; +#endif +}; } // namespace BaseLib + +#include "TemplateLogogFormatterSuppressedGCC-impl.h" + +#endif // TEMPLATELOGOGFORMATTERSUPPRESSEDGCC_H_