v0.14.0
Functions | Variables
log.cpp File Reference
#include <MoFEM.hpp>
#include <thread>
#include <chrono>

Go to the source code of this file.

Functions

MoFEMErrorCode log_fun1 ()
 
MoFEMErrorCode log_fun3 ()
 
MoFEMErrorCode log_fun2 ()
 
int main (int argc, char *argv[])
 

Variables

static char help [] = "...\n\n"
 

Function Documentation

◆ log_fun1()

MoFEMErrorCode log_fun1 ( )
Examples
log.cpp.

Definition at line 17 of file log.cpp.

17  {
19 
20  MOFEM_LOG_CHANNEL("WORLD");
21  // Log time
22  BOOST_LOG_SCOPED_THREAD_ATTR("Timeline", attrs::timer());
23  // Log tag
24  MOFEM_LOG_TAG("WORLD", "Tag this output");
25 
26  MOFEM_LOG("WORLD", Sev::verbose) << "Hello, world!";
27 
28  // sleep for half a second
29  std::this_thread::sleep_for(std::chrono::milliseconds(300));
30 
31  MOFEM_LOG("WORLD", Sev::verbose) << "Hello, second time world!";
32 
34 }

◆ log_fun2()

MoFEMErrorCode log_fun2 ( )
Examples
log.cpp.

Definition at line 47 of file log.cpp.

47  {
49 
50  // Log scope
52  MOFEM_LOG_CHANNEL("SYNC");
53  MOFEM_LOG_ATTRIBUTES("SYNC", LogManager::BitLineID | LogManager::BitScope);
54  MOFEM_LOG("SYNC", Sev::verbose) << "Hello, sync!";
55  MOFEM_LOG("SYNC", Sev::verbose) << "Hello again, sync!";
56 
57  CHKERR log_fun3();
58 
60 }

◆ log_fun3()

MoFEMErrorCode log_fun3 ( )
Examples
log.cpp.

Definition at line 36 of file log.cpp.

36  {
39 
40  // Log scope
41  MOFEM_LOG("SYNC", Sev::verbose) << "Hello, sync!";
42  MOFEM_LOG("SYNC", Sev::verbose) << "Hello again, sync!";
43 
45 }

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples
log.cpp.

Definition at line 64 of file log.cpp.

64  {
65 
66  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
67 
68  try {
69 
70  moab::Core mb_instance;
71  moab::Interface &moab = mb_instance;
72 
73  MoFEM::Core core(moab, PETSC_COMM_WORLD);
74  MoFEM::Interface &m_field = core;
75 
76  CHKERR PetscPrintf(PETSC_COMM_WORLD,
77  "\nTesting logging for obsolete way of printing "
78  "messages\nnext line\nnext line\n\n");
79 
80  CHKERR PetscPrintf(PETSC_COMM_WORLD,
81  "Ala have ");
82  CHKERR PetscPrintf(PETSC_COMM_WORLD, "a ");
83  CHKERR PetscPrintf(PETSC_COMM_WORLD,
84  "cat\n");
85 
86  CHKERR PetscPrintf(PETSC_COMM_WORLD, "WARNING\n");
87 
88  // Set "WORLD channel"
89  MOFEM_LOG_CHANNEL("WORLD");
90  {
91  MOFEM_LOG("WORLD", Sev::error) << "Hello, self error!";
92  MOFEM_LOG("WORLD", Sev::warning) << "Hello, self warning!";
93  MOFEM_LOG("WORLD", Sev::inform) << "Hello, self inform!";
94  MOFEM_LOG("WORLD", Sev::verbose) << "Hello, self verbose!";
95  MOFEM_LOG("WORLD", Sev::noisy) << "Hello, self noisy!";
96  }
97 
98  {
99  MOFEM_LOG_C("WORLD", Sev::inform, "%s %d %d %d", "Hello C, self error!",
100  1, 2, 3);
101  }
102 
103  {
104  CHKERR log_fun1();
105  CHKERR log_fun2();
106  MOFEM_LOG_SYNCHRONISE(m_field.get_comm());
107  }
108 
109  // Create channel
110  auto core_log = logging::core::get();
111  core_log->add_sink(
112  LogManager::createSink(LogManager::getStrmSelf(), "ATOM_TEST"));
113  LogManager::setLog("ATOM_TEST");
114 
115  // add sink to channel
116  core_log->add_sink(LogManager::createSink(
117  boost::make_shared<std::ofstream>("log0.log"), "ATOM_TEST"));
118 
119  // add sink to channel other way
120  logging::add_file_log(keywords::file_name = "log1.log",
121  keywords::filter =
122  MoFEM::LogKeywords::channel == "ATOM_TEST");
123 
124  // add skink to channel third way
125  auto backend = boost::make_shared<sinks::text_ostream_backend>();
126  backend->add_stream(boost::make_shared<std::ofstream>("log2.log"));
127  auto sink = boost::make_shared<LogManager::SinkType>(backend);
128  sink->set_filter((expr::has_attr(MoFEM::LogKeywords::channel) &&
129  MoFEM::LogKeywords::channel == "ATOM_TEST"));
130  core_log->add_sink(sink);
131 
132 
133  MOFEM_LOG_TAG("ATOM_TEST", "atom test");
134  MOFEM_LOG("ATOM_TEST", Sev::inform) << "Test atom test channel";
135 
136 
137  // SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY, "Trigger error");
138  }
139  CATCH_ERRORS;
140 
142 }

Variable Documentation

◆ help

char help[] = "...\n\n"
static
Examples
log.cpp.

Definition at line 62 of file log.cpp.

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
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::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
MOFEM_LOG_FUNCTION
#define MOFEM_LOG_FUNCTION()
Set scope.
Definition: LogManager.hpp:325
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
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
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:385
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359