v0.14.0
Loading...
Searching...
No Matches
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}
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.

◆ 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");
54 MOFEM_LOG("SYNC", Sev::verbose) << "Hello, sync!";
55 MOFEM_LOG("SYNC", Sev::verbose) << "Hello again, sync!";
56
58
60}
#define CHKERR
Inline error check.
#define MOFEM_LOG_ATTRIBUTES(channel, bit)
Add attributes to channel.
#define MOFEM_LOG_FUNCTION()
Set scope.
MoFEMErrorCode log_fun3()
Definition log.cpp:36

◆ 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[] )

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 {
107 }
108
109 // Create channel
110 auto core_log = logging::core::get();
111 core_log->add_sink(
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 }
140
142}
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
#define MOFEM_LOG_C(channel, severity, format,...)
#define CATCH_ERRORS
Catch errors.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
static char help[]
Definition log.cpp:62
MoFEMErrorCode log_fun1()
Definition log.cpp:17
MoFEMErrorCode log_fun2()
Definition log.cpp:47
virtual MPI_Comm & get_comm() const =0
Core (interface) class.
Definition Core.hpp:82
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
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:112
Deprecated interface functions.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.

Variable Documentation

◆ help

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

Definition at line 62 of file log.cpp.