Skip to content
Snippets Groups Projects
Commit 36c4a81a authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Set log pattern for mpi

parent 4bb167c1
No related branches found
No related tags found
No related merge requests found
......@@ -121,7 +121,8 @@ int main(int argc, char* argv[])
std::cout.setf(std::ios::unitbuf);
}
logog_setup.setLevel(log_level_arg.getValue());
BaseLib::setConsoleLogLevel(log_level_arg.getValue());
spdlog::set_pattern("%^%l:%$ %v");
INFO("This is OpenGeoSys-6 version {:s}.",
GitInfoLib::GitInfo::ogs_version);
......@@ -166,10 +167,11 @@ int main(int argc, char* argv[])
controller->Initialize(&argc, &argv, 1);
vtkMPIController::SetGlobalController(controller);
logog_setup.setFormatter(
std::make_unique<BaseLib::TemplateLogogFormatterSuppressedGCC<
TOPIC_LEVEL_FLAG | TOPIC_FILE_NAME_FLAG |
TOPIC_LINE_NUMBER_FLAG>>());
{ // Can be called only after MPI_INIT.
int mpi_rank;
MPI_Comm_rank(PETSC_COMM_WORLD, &mpi_rank);
spdlog::set_pattern(fmt::format("[{}] %^%l:%$ %v", mpi_rank));
}
#endif
run_time.start();
......
......@@ -10,13 +10,25 @@
*/
#include "Logging.h"
#include <spdlog/sinks/stdout_color_sinks.h>
#include <map>
#ifdef USE_PETSC
#include <mpi.h>
#include <petscsys.h>
#endif
#include "Error.h"
namespace BaseLib
{
#ifdef USE_PETSC
std::shared_ptr<spdlog::logger> console = spdlog::stdout_color_mt("ogs");
#else // USE_PETSC
std::shared_ptr<spdlog::logger> console = spdlog::stdout_color_st("ogs");
#endif // USE_PETSC
void setConsoleLogLevel(std::string const& level_string)
{
......
......@@ -12,15 +12,13 @@
*
*/
// ** INCLUDES **
#include <clocale>
#include "gtest/gtest.h"
#include "Applications/ApplicationsLib/LogogSetup.h"
#include "Applications/ApplicationsLib/LinearSolverLibrarySetup.h"
#include "BaseLib/Error.h"
#include "BaseLib/Logging.h"
#include "NumLib/DOF/GlobalMatrixProviders.h"
#include "BaseLib/TemplateLogogFormatterSuppressedGCC.h"
#include "gtest/gtest.h"
#ifdef OGS_BUILD_GUI
#include <QCoreApplication>
......@@ -51,24 +49,22 @@ int main(int argc, char* argv[])
QCoreApplication app(argc, argv, false);
#endif
// Attention: Order matters!
// logog_setup must be created first, then the linear_solver_library_setup,
// because destruction order is the reverse of the creation order and the
// destructor of linear_solver_library_setup might print log messages.
// The methods on logog_setup must be called after the construction of
// linear_solver_library_setup since they require, e.g., that MPI_Init()
// has been called before.
ApplicationsLib::LogogSetup logog_setup;
ApplicationsLib::LinearSolverLibrarySetup linear_solver_library_setup(
argc, argv);
logog_setup.setFormatter(
std::make_unique<BaseLib::TemplateLogogFormatterSuppressedGCC<
TOPIC_LEVEL_FLAG | TOPIC_FILE_NAME_FLAG |
TOPIC_LINE_NUMBER_FLAG>>());
logog_setup.setLevel(logLevel);
BaseLib::setConsoleLogLevel(logLevel);
spdlog::set_pattern("%^%l:%$ %v");
spdlog::set_error_handler([](const std::string& msg) {
std::cerr << "spdlog error: " << msg << std::endl;
OGS_FATAL("spdlog logger error occured.");
});
#ifdef USE_PETSC
{ // Can be called only after MPI_INIT.
int mpi_rank;
MPI_Comm_rank(PETSC_COMM_WORLD, &mpi_rank);
spdlog::set_pattern(fmt::format("[{}] %^%l:%$ %v", mpi_rank));
}
#endif
try
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment