v0.14.0
log.cpp

Example and test how to logThis is an example of how to use the logger.

/**
* @file log.cpp
* @example log.cpp
* @brief Example and test how to log
*
* This is an example of how to use the logger.
*
*/
#include <MoFEM.hpp>
#include <thread>
#include <chrono>
using namespace MoFEM;
// Log time
BOOST_LOG_SCOPED_THREAD_ATTR("Timeline", attrs::timer());
// Log tag
MOFEM_LOG_TAG("WORLD", "Tag this output");
MOFEM_LOG("WORLD", Sev::verbose) << "Hello, world!";
// sleep for half a second
std::this_thread::sleep_for(std::chrono::milliseconds(300));
MOFEM_LOG("WORLD", Sev::verbose) << "Hello, second time world!";
}
// Log scope
MOFEM_LOG("SYNC", Sev::verbose) << "Hello, sync!";
MOFEM_LOG("SYNC", Sev::verbose) << "Hello again, sync!";
}
// Log scope
MOFEM_LOG("SYNC", Sev::verbose) << "Hello, sync!";
MOFEM_LOG("SYNC", Sev::verbose) << "Hello again, sync!";
}
static char help[] = "...\n\n";
int main(int argc, char *argv[]) {
MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
try {
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
MoFEM::Core core(moab, PETSC_COMM_WORLD);
MoFEM::Interface &m_field = core;
CHKERR PetscPrintf(PETSC_COMM_WORLD,
"\nTesting logging for obsolete way of printing "
"messages\nnext line\nnext line\n\n");
CHKERR PetscPrintf(PETSC_COMM_WORLD,
"Ala have ");
CHKERR PetscPrintf(PETSC_COMM_WORLD, "a ");
CHKERR PetscPrintf(PETSC_COMM_WORLD,
"cat\n");
CHKERR PetscPrintf(PETSC_COMM_WORLD, "WARNING\n");
// Set "WORLD channel"
{
MOFEM_LOG("WORLD", Sev::error) << "Hello, self error!";
MOFEM_LOG("WORLD", Sev::warning) << "Hello, self warning!";
MOFEM_LOG("WORLD", Sev::inform) << "Hello, self inform!";
MOFEM_LOG("WORLD", Sev::verbose) << "Hello, self verbose!";
MOFEM_LOG("WORLD", Sev::noisy) << "Hello, self noisy!";
}
{
MOFEM_LOG_C("WORLD", Sev::inform, "%s %d %d %d", "Hello C, self error!",
1, 2, 3);
}
{
}
// Create channel
auto core_log = logging::core::get();
core_log->add_sink(
LogManager::setLog("ATOM_TEST");
// add sink to channel
core_log->add_sink(LogManager::createSink(
boost::make_shared<std::ofstream>("log0.log"), "ATOM_TEST"));
// add sink to channel other way
logging::add_file_log(keywords::file_name = "log1.log",
keywords::filter =
MoFEM::LogKeywords::channel == "ATOM_TEST");
// add skink to channel third way
auto backend = boost::make_shared<sinks::text_ostream_backend>();
backend->add_stream(boost::make_shared<std::ofstream>("log2.log"));
auto sink = boost::make_shared<LogManager::SinkType>(backend);
sink->set_filter((expr::has_attr(MoFEM::LogKeywords::channel) &&
MoFEM::LogKeywords::channel == "ATOM_TEST"));
core_log->add_sink(sink);
MOFEM_LOG_TAG("ATOM_TEST", "atom test");
MOFEM_LOG("ATOM_TEST", Sev::inform) << "Test atom test channel";
// SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY, "Trigger error");
}
}
main
int main(int argc, char *argv[])
Definition: log.cpp:64
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
log_fun1
MoFEMErrorCode log_fun1()
Definition: log.cpp:17
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
log_fun3
MoFEMErrorCode log_fun3()
Definition: log.cpp:36
MOFEM_LOG_ATTRIBUTES
#define MOFEM_LOG_ATTRIBUTES(channel, bit)
Add attributes to channel.
Definition: LogManager.hpp:296
MoFEM.hpp
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::LogManager::createSink
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
Definition: LogManager.cpp:298
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
MOFEM_LOG_FUNCTION
#define MOFEM_LOG_FUNCTION()
Set scope.
Definition: LogManager.hpp:325
MoFEM::LogManager::BitLineID
@ BitLineID
Definition: LogManager.hpp:48
MoFEM::LogManager::BitScope
@ BitScope
Definition: LogManager.hpp:49
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MOFEM_LOG_C
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:311
MOFEM_LOG_SYNCHRONISE
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
Definition: LogManager.hpp:345
MoFEM::LogManager::getStrmSelf
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
Definition: LogManager.cpp:340
log_fun2
MoFEMErrorCode log_fun2()
Definition: log.cpp:47
MOFEM_LOG_TAG
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
Definition: LogManager.hpp:339
help
static char help[]
Definition: log.cpp:62
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
MoFEM::LogManager::setLog
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
Definition: LogManager.cpp:389
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346