v0.15.0
Loading...
Searching...
No Matches
MoFEM::LogManager Struct Reference

Log manager is used to build and partition problems. More...

#include "src/interfaces/LogManager.hpp"

Inheritance diagram for MoFEM::LogManager:
[legend]
Collaboration diagram for MoFEM::LogManager:
[legend]

Classes

struct  InternalData
 

Public Types

enum  SeverityLevel {
  noisy , verbose , inform , warning ,
  error
}
 Severity levels. More...
 
enum  LogAttributesBits { BitLineID = 1 << 0 , BitScope = 1 << 1 }
 Tag attributes switches. More...
 
typedef boost::log::sources::severity_channel_logger< SeverityLevel, std::string > LoggerType
 Definition of the channel logger.
 
typedef sinks::synchronous_sink< sinks::text_ostream_backend > SinkType
 

Public Member Functions

MoFEMErrorCode query_interface (boost::typeindex::type_index type_index, UnknownInterface **iface) const
 
 LogManager (const MoFEM::Core &core)
 
virtual ~LogManager ()=default
 
- Public Member Functions inherited from MoFEM::UnknownInterface
template<class IFACE >
MoFEMErrorCode registerInterface (bool error_if_registration_failed=true)
 Register interface.
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE *&iface) const
 Get interface reference to pointer of interface.
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE **const iface) const
 Get interface pointer to pointer of interface.
 
template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get interface pointer to pointer of interface.
 
template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get reference to interface.
 
template<class IFACE >
IFACE * getInterface () const
 Function returning pointer to interface.
 
virtual ~UnknownInterface ()=default
 

Static Public Member Functions

static void addAttributes (LogManager::LoggerType &lg, const int bit=0)
 Add attributes to logger.
 
static void addAttributes (const std::string channel, const int bit=0)
 Add attributes to channel.
 
static LoggerTypesetLog (const std::string channel)
 Set ans resset chanel logger.
 
static LoggerTypegetLog (const std::string channel)
 Get logger by channel.
 
static bool checkIfChannelExist (const std::string channel)
 Check if channel exist.
 
static void addTag (LogManager::LoggerType &lg, const std::string tag)
 Add tag to logger.
 
static void addTag (const std::string channel, const std::string tag)
 Add tag to channel.
 
static boost::shared_ptr< std::ostream > getStrmSelf ()
 Get the strm self object.
 
static boost::shared_ptr< std::ostream > getStrmWorld ()
 Get the strm world object.
 
static boost::shared_ptr< std::ostream > getStrmSync ()
 Get the strm sync object.
 
static boost::shared_ptr< std::ostream > getStrmNull ()
 Get the strm null object.
 
static boost::shared_ptr< std::ostream > getStrmSync (MPI_Comm comm, FILE *fd)
 Get the strm sync object.
 
static boost::shared_ptr< SinkTypecreateSink (boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
 Create a sink object.
 
static void createDefaultSinks (MPI_Comm comm)
 Create default sinks.
 
static MoFEMErrorCode getOptions ()
 Get logger option.
 
static PetscErrorCode logPetscFPrintf (FILE *fd, const char format[], va_list Argp)
 Use to handle PETSc output.
 
static std::string getVLikeFormatedString (const char *fmt, va_list args)
 Converts formatted output to string.
 
static std::string getCLikeFormatedString (const char *fmt,...)
 Converts formatted output to string.
 
static void recordFormatterDefault (logging::record_view const &rec, logging::formatting_ostream &strm)
 Default record formatter.
 
- Static Public Member Functions inherited from MoFEM::UnknownInterface
static MoFEMErrorCode getLibVersion (Version &version)
 Get library version.
 
static MoFEMErrorCode getFileVersion (moab::Interface &moab, Version &version)
 Get database major version.
 
static MoFEMErrorCode setFileVersion (moab::Interface &moab, Version version=Version(MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR, MoFEM_VERSION_BUILD))
 Get database major version.
 
static MoFEMErrorCode getInterfaceVersion (Version &version)
 Get database major version.
 

Static Public Attributes

static constexpr std::array< char *const, error+1 > severityStrings
 
static FILE * dummy_mofem_fd = (FILE *)&dummy_file
 Dummy file pointer (DO NOT USE)
 

Private Attributes

MoFEM::CorecOre
 

Static Private Attributes

static boost::shared_ptr< InternalDatainternalDataPtr
 
static std::string petscStringCache = std::string()
 

Detailed Description

Log manager is used to build and partition problems.

Examples
elasticity.cpp.

Definition at line 26 of file LogManager.hpp.

Member Typedef Documentation

◆ LoggerType

boost::log::sources::severity_channel_logger<SeverityLevel, std::string> MoFEM::LogManager::LoggerType

Definition of the channel logger.

Definition at line 64 of file LogManager.hpp.

◆ SinkType

sinks::synchronous_sink<sinks::text_ostream_backend> MoFEM::LogManager::SinkType

Definition at line 66 of file LogManager.hpp.

Constructor & Destructor Documentation

◆ LogManager()

MoFEM::LogManager::LogManager ( const MoFEM::Core & core)

Definition at line 138 of file LogManager.cpp.

139 : cOre(const_cast<MoFEM::Core &>(core)) {}
Core (interface) class.
Definition Core.hpp:82
MoFEM::Core & cOre

◆ ~LogManager()

virtual MoFEM::LogManager::~LogManager ( )
virtualdefault

Member Function Documentation

◆ checkIfChannelExist()

bool MoFEM::LogManager::checkIfChannelExist ( const std::string channel)
static

Check if channel exist.

Parameters
channel
Returns
true
false

Definition at line 407 of file LogManager.cpp.

407 {
408 return InternalData::logChannels.find(channel) !=
410}
static std::map< std::string, LoggerType > logChannels

◆ createDefaultSinks()

void MoFEM::LogManager::createDefaultSinks ( MPI_Comm comm)
static

Create default sinks.

Definition at line 308 of file LogManager.cpp.

308 {
309
310 internalDataPtr = boost::make_shared<InternalData>(comm);
311
312 auto core_log = logging::core::get();
313 core_log->remove_all_sinks();
314 core_log->add_sink(LogManager::createSink(
315 boost::shared_ptr<std::ostream>(&std::clog, boost::null_deleter()),
316 "PETSC"));
317 core_log->add_sink(createSink(getStrmSelf(), "SELF"));
318 core_log->add_sink(createSink(getStrmWorld(), "WORLD"));
319 core_log->add_sink(createSink(getStrmSync(), "SYNC"));
320 core_log->add_sink(createSink(getStrmNull(), "NULL"));
321
322 LogManager::setLog("PETSC");
323 LogManager::setLog("SELF");
324 LogManager::setLog("WORLD");
325 LogManager::setLog("SYNC");
326 LogManager::setLog("NULL");
327
328 MOFEM_LOG_TAG("PETSC", "petsc");
329
330 int rank;
331 MPI_Comm_rank(comm, &rank);
332 core_log->add_global_attribute("Proc", attrs::constant<unsigned int>(rank));
333}
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
static boost::shared_ptr< std::ostream > getStrmNull()
Get the strm null object.
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 > getStrmWorld()
Get the strm world object.
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
static boost::shared_ptr< InternalData > internalDataPtr

◆ createSink()

boost::shared_ptr< LogManager::SinkType > MoFEM::LogManager::createSink ( boost::shared_ptr< std::ostream > stream_ptr,
std::string comm_filter )
static

Create a sink object.

Parameters
stream_ptr
comm_filter
Returns
boost::shared_ptr<SinkType>

Definition at line 293 of file LogManager.cpp.

294 {
295
296 auto backend = boost::make_shared<sinks::text_ostream_backend>();
297 if (stream_ptr)
298 backend->add_stream(stream_ptr);
299 backend->auto_flush(true);
300
301 auto sink = boost::make_shared<SinkType>(backend);
302 sink->set_filter((expr::has_attr(channel) && channel == comm_filter));
303 sink->set_formatter(&recordFormatterDefault);
304
305 return sink;
306}
static void recordFormatterDefault(logging::record_view const &rec, logging::formatting_ostream &strm)
Default record formatter.

◆ getCLikeFormatedString()

std::string MoFEM::LogManager::getCLikeFormatedString ( const char * fmt,
... )
static

Converts formatted output to string.

Parameters
fmt
args
Returns
std::string

Definition at line 474 of file LogManager.cpp.

474 {
475 va_list args;
476 va_start(args, fmt);
477 auto str = getVLikeFormatedString(fmt, args);
478 va_end(args);
479 return str;
480}
static std::string getVLikeFormatedString(const char *fmt, va_list args)
Converts formatted output to string.

◆ getOptions()

MoFEMErrorCode MoFEM::LogManager::getOptions ( )
static

Get logger option.

This function is called by MoFEM core when this interface is registred into database.

Returns
MoFEMErrorCode

Definition at line 149 of file LogManager.cpp.

149 {
151 PetscInt sev_level = SeverityLevel::inform;
152 PetscBool log_scope = PETSC_FALSE;
153 PetscBool log_quiet = PETSC_FALSE;
154 PetscBool log_no_colors = PETSC_FALSE;
155 PetscBool log_time = PETSC_FALSE;
156
157 PetscOptionsBegin(PETSC_COMM_WORLD, "log_", "Logging interface options",
158 "none");
159
160 CHKERR PetscOptionsEList("-severity_level", "Severity level", "",
162 severityStrings[sev_level], &sev_level,
163 PETSC_NULLPTR);
164 CHKERR PetscOptionsEList("-sl", "Severity level", "", severityStrings.data(),
166 &sev_level, PETSC_NULLPTR);
167
168 CHKERR PetscOptionsBool("-scope", "Log scope", "", log_scope, &log_scope,
169 NULL);
170
171 CHKERR PetscOptionsBool("-quiet", "Quiet log attributes", "", log_quiet,
172 &log_quiet, NULL);
173
174 CHKERR PetscOptionsBool("-no_color", "Terminal with no colors", "",
175 log_no_colors, &log_no_colors, NULL);
176 CHKERR PetscOptionsBool("-nc", "Terminal with no colors", "", log_no_colors,
177 &log_no_colors, NULL);
178
179 CHKERR PetscOptionsBool("-time", "Log time", "", log_time, &log_time, NULL);
180
181 PetscOptionsEnd();
182
183 logging::core::get()->set_filter(MoFEM::LogKeywords::severity >= sev_level);
184
185 if (log_scope)
186 logging::core::get()->add_global_attribute("Scope", attrs::named_scope());
187
188 if (log_quiet)
190
191 if (log_no_colors)
193
194 if (log_time)
196
198}
#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 CHKERR
Inline error check.
static constexpr std::array< char *const, error+1 > severityStrings

◆ getStrmNull()

boost::shared_ptr< std::ostream > MoFEM::LogManager::getStrmNull ( )
static

Get the strm null object.

Returns
boost::shared_ptr<std::ostream>

Definition at line 347 of file LogManager.cpp.

347 {
348 return internalDataPtr->getStrmNull();
349}

◆ getStrmSelf()

boost::shared_ptr< std::ostream > MoFEM::LogManager::getStrmSelf ( )
static

Get the strm self object.

Returns
boost::shared_ptr<std::ostream>

Definition at line 335 of file LogManager.cpp.

335 {
336 return internalDataPtr->getStrmSelf();
337}

◆ getStrmSync() [1/2]

boost::shared_ptr< std::ostream > MoFEM::LogManager::getStrmSync ( )
static

Get the strm sync object.

Returns
boost::shared_ptr<std::ostream>

Definition at line 343 of file LogManager.cpp.

343 {
344 return internalDataPtr->getStrmSync();
345}

◆ getStrmSync() [2/2]

boost::shared_ptr< std::ostream > MoFEM::LogManager::getStrmSync ( MPI_Comm comm,
FILE * fd )
static

Get the strm sync object.

Parameters
comm
fd
Returns
boost::shared_ptr<std::ostream>

Definition at line 351 of file LogManager.cpp.

352 {
353 auto buff_ptr =
354 boost::make_shared<InternalData::SynchronizedStreamBuf>(comm, fd);
355 return boost::shared_ptr<std::ostream>(buff_ptr,
356 new std::ostream(buff_ptr.get()));
357}

◆ getStrmWorld()

boost::shared_ptr< std::ostream > MoFEM::LogManager::getStrmWorld ( )
static

Get the strm world object.

Returns
boost::shared_ptr<std::ostream>

Definition at line 339 of file LogManager.cpp.

339 {
340 return internalDataPtr->getStrmWorld();
341}

◆ getVLikeFormatedString()

std::string MoFEM::LogManager::getVLikeFormatedString ( const char * fmt,
va_list args )
static

Converts formatted output to string.

Parameters
fmt
args
Returns
std::string

Definition at line 468 of file LogManager.cpp.

468 {
469 std::array<char, 1024> buf;
470 vsprintf(buf.data(), fmt, args);
471 return std::string(buf.data());
472}

◆ logPetscFPrintf()

PetscErrorCode MoFEM::LogManager::logPetscFPrintf ( FILE * fd,
const char format[],
va_list Argp )
static

Use to handle PETSc output.

Note
This is for internal use only/
Parameters
fd
format
Argp
Returns
PetscErrorCode

Definition at line 414 of file LogManager.cpp.

415 {
417 if (fd != stdout && fd != stderr && fd != dummy_mofem_fd) {
418 CHKERR PetscVFPrintfDefault(fd, format, Argp);
419
420 } else {
421
422 std::array<char, 1024> buff;
423 size_t length;
424 CHKERR PetscVSNPrintf(buff.data(), 1024, format, &length, Argp);
425
426 auto get_str = [&buff]() {
427 std::string str;
428 if (!petscStringCache.empty())
429 str = petscStringCache + std::string(buff.data());
430 else
431 str = std::string(buff.data());
432 return str;
433 };
434 const auto str = get_str();
435
436 if (!str.empty()) {
437 if (fd != dummy_mofem_fd) {
438
441 if (str.find("WARNING") != std::string::npos)
443
444 std::istringstream is(str);
445 std::string line;
446 std::vector<std::string> log_list;
447
448 while (getline(is, line, '\n'))
449 log_list.push_back(line);
450
451 if (str.back() != '\n') {
452 petscStringCache = log_list.back();
453 log_list.pop_back();
454 } else
455 petscStringCache.clear();
456
457 for (auto &line : log_list)
458 MOFEM_LOG("PETSC", sev) << line;
459
460 } else {
461 std::clog << str;
462 }
463 }
464 }
466}
PetscErrorCode PetscVFPrintfDefault(FILE *fd, const char *format, va_list Argp)
#define MOFEM_LOG(channel, severity)
Log.
SeverityLevel
Severity levels.
static std::string petscStringCache
static FILE * dummy_mofem_fd
Dummy file pointer (DO NOT USE)

◆ query_interface()

MoFEMErrorCode MoFEM::LogManager::query_interface ( boost::typeindex::type_index type_index,
UnknownInterface ** iface ) const
virtual

Implements MoFEM::UnknownInterface.

Definition at line 142 of file LogManager.cpp.

143 {
145 *iface = const_cast<LogManager *>(this);
147}
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
LogManager(const MoFEM::Core &core)

◆ recordFormatterDefault()

void MoFEM::LogManager::recordFormatterDefault ( logging::record_view const & rec,
logging::formatting_ostream & strm )
static

Default record formatter.

Parameters
rec
strm

Definition at line 200 of file LogManager.cpp.

201 {
202
204
205 auto sev = rec[severity];
206 auto p = rec[proc_attr];
207 auto l = rec[line_id];
208 auto s = rec[scope];
209 auto tg = rec[tag_attr];
210 auto tl = rec[timeline];
211
212 auto set_color = [&](const auto str) {
213#if defined(PETSC_HAVE_UNISTD_H) && defined(PETSC_USE_ISATTY)
214 if (isatty(fileno(stdout)) && !LogManager::InternalData::noColors)
215 strm << str;
216#endif
217 };
218
220
221 auto local_time = boost::posix_time::second_clock::local_time();
222 strm << "(Local time ";
223 strm << local_time.date().year() << "-" << local_time.date().month()
224 << "-" << local_time.date().day() << " "
225 << local_time.time_of_day().hours() << ":"
226 << local_time.time_of_day().minutes() << ":"
227 << local_time.time_of_day().seconds();
228 strm << ") ";
229 }
230
231 if (!p.empty()) {
232 strm << "[";
233 set_color("\033[32m");
234 strm << p;
235 set_color("\033[0m");
236 strm << "] ";
237 }
238
239 switch (sev.get()) {
241 set_color("\033[1m");
243 set_color("\033[31m");
244 break;
246 set_color("\033[34m");
247 break;
249 set_color("\033[35m");
250 break;
252 set_color("\033[36m");
253 break;
254 }
255
256 strm << sev;
257
258 set_color("\033[0m");
259
260 if (!l.empty())
261 strm << std::hex << std::setw(8) << std::setfill('0') << l.get()
262 << std::dec << std::setfill(' ') << ": ";
263
264 if (!s.empty()) {
265 for (::boost::log::attributes::named_scope_list::const_iterator iter =
266 s->begin();
267 iter != s->end(); ++iter) {
268 const auto path = std::string(iter->file_name.data());
269 const auto file = path.substr(path.find_last_of("/\\") + 1);
270 strm << "(" << file << ":" << iter->line << ">" << iter->scope_name
271 << ")";
272 }
273 strm << " ";
274 }
275
276 if (!tg.empty()) {
277
278 set_color("\033[1m");
279 strm << "[" << tg.get() << "] ";
280 set_color("\033[0m");
281 }
282
283 if (!tl.empty())
284 strm << "[" << tl.get() << "] ";
285 }
286
287 auto msg = rec[logging::expressions::smessage];
288
289 strm << msg;
290}
FTensor::Index< 'l', 3 > l

Member Data Documentation

◆ cOre

MoFEM::Core& MoFEM::LogManager::cOre
private

Definition at line 243 of file LogManager.hpp.

◆ dummy_mofem_fd

FILE * MoFEM::LogManager::dummy_mofem_fd = (FILE *)&dummy_file
static

Dummy file pointer (DO NOT USE)

Note
This is for internal use only/

Definition at line 200 of file LogManager.hpp.

◆ internalDataPtr

boost::shared_ptr< LogManager::InternalData > MoFEM::LogManager::internalDataPtr
staticprivate

Definition at line 246 of file LogManager.hpp.

◆ petscStringCache

std::string MoFEM::LogManager::petscStringCache = std::string()
staticprivate

Definition at line 248 of file LogManager.hpp.

◆ severityStrings

std::array<char *const, error + 1> MoFEM::LogManager::severityStrings
inlinestaticconstexpr
Initial value:
= {
(char *)"noisy", (char *)"verbose", (char *)"inform", (char *)"warning",
(char *)"error"
}

Definition at line 35 of file LogManager.hpp.

35 {
36
37 (char *)"noisy", (char *)"verbose", (char *)"inform", (char *)"warning",
38 (char *)"error"
39
40 };

The documentation for this struct was generated from the following files: