v0.13.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | Static Private Attributes | List of all members
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. More...
 
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. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE *&iface) const
 Get interface refernce to pointer of interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE **const iface) const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get reference to interface. More...
 
template<class IFACE >
IFACE * getInterface () const
 Function returning pointer to interface. More...
 
virtual ~UnknownInterface ()=default
 

Static Public Member Functions

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

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) More...
 

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.

Definition at line 36 of file LogManager.hpp.

Member Typedef Documentation

◆ LoggerType

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

Definition of the channel logger.

Definition at line 74 of file LogManager.hpp.

◆ SinkType

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

Definition at line 76 of file LogManager.hpp.

Constructor & Destructor Documentation

◆ LogManager()

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

Definition at line 122 of file LogManager.cpp.

123  : cOre(const_cast<MoFEM::Core &>(core)) {}
Core (interface) class.
Definition: Core.hpp:92
MoFEM::Core & cOre
Definition: LogManager.hpp:237

◆ ~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 374 of file LogManager.cpp.

374  {
375  return InternalData::logChannels.find(channel) !=
377 }
static std::map< std::string, LoggerType > logChannels
Definition: LogManager.cpp:93

◆ createDefaultSinks()

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

Create default sinks.

Definition at line 294 of file LogManager.cpp.

294  {
295 
296  internalDataPtr = boost::make_shared<InternalData>(comm);
297 
298  auto core_log = logging::core::get();
299  core_log->remove_all_sinks();
300  core_log->add_sink(LogManager::createSink(
301  boost::shared_ptr<std::ostream>(&std::clog, boost::null_deleter()),
302  "PETSC"));
303  core_log->add_sink(createSink(getStrmSelf(), "SELF"));
304  core_log->add_sink(createSink(getStrmWorld(), "WORLD"));
305  core_log->add_sink(createSink(getStrmSync(), "SYNC"));
306 
307  LogManager::setLog("PETSC");
308  LogManager::setLog("SELF");
309  LogManager::setLog("WORLD");
310  LogManager::setLog("SYNC");
311 
312  MOFEM_LOG_TAG("PETSC", "petsc");
313 
314  int rank;
315  MPI_Comm_rank(comm, &rank);
316  core_log->add_global_attribute("Proc", attrs::constant<unsigned int>(rank));
317 }
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
Definition: LogManager.cpp:364
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
Definition: LogManager.hpp:342
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
Definition: LogManager.cpp:279
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
Definition: LogManager.cpp:323
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
Definition: LogManager.cpp:327
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
Definition: LogManager.cpp:319
static boost::shared_ptr< InternalData > internalDataPtr
Definition: LogManager.hpp:239

◆ 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>
Examples
add_cubit_meshsets.cpp, approx_sphere.cpp, contact.cpp, continuity_check_on_skeleton_3d.cpp, continuity_check_on_skeleton_with_simple_2d_for_h1.cpp, continuity_check_on_skeleton_with_simple_2d_for_hcurl.cpp, eigen_elastic.cpp, elasticity.cpp, ep.cpp, free_surface.cpp, heat_method.cpp, log.cpp, matrix_function.cpp, mixed_poisson.cpp, nonlinear_dynamics.cpp, nonlinear_elastic.cpp, plastic.cpp, plate.cpp, plot_base.cpp, scalar_check_approximation.cpp, shallow_wave.cpp, split_sideset.cpp, and thermo_plastic.cpp.

Definition at line 279 of file LogManager.cpp.

280  {
281 
282  auto backend = boost::make_shared<sinks::text_ostream_backend>();
283  if (stream_ptr)
284  backend->add_stream(stream_ptr);
285  backend->auto_flush(true);
286 
287  auto sink = boost::make_shared<SinkType>(backend);
288  sink->set_filter((expr::has_attr(channel) && channel == comm_filter));
289  sink->set_formatter(&recordFormatterDefault);
290 
291  return sink;
292 }
static void recordFormatterDefault(logging::record_view const &rec, logging::formatting_ostream &strm)
Default record formatter.
Definition: LogManager.cpp:185

◆ getCLikeFormatedString()

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

Converts formatted output to string.

Parameters
fmt
args
Returns
std::string

Definition at line 441 of file LogManager.cpp.

441  {
442  va_list args;
443  va_start(args, fmt);
444  auto str = getVLikeFormatedString(fmt, args);
445  va_end(args);
446  return str;
447 }
static std::string getVLikeFormatedString(const char *fmt, va_list args)
Converts formatted output to string.
Definition: LogManager.cpp:435

◆ 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 133 of file LogManager.cpp.

133  {
135  PetscInt sev_level = SeverityLevel::inform;
136  PetscBool log_scope = PETSC_FALSE;
137  PetscBool log_quiet = PETSC_FALSE;
138  PetscBool log_no_colors = PETSC_FALSE;
139  PetscBool log_time = PETSC_FALSE;
140 
141  CHKERR PetscOptionsBegin(PETSC_COMM_WORLD, "log_",
142  "Logging interface options", "none");
143 
144  CHKERR PetscOptionsEList("-severity_level", "Severity level", "",
145  severityStrings.data(), SeverityLevel::error + 1,
146  severityStrings[sev_level], &sev_level, PETSC_NULL);
147  CHKERR PetscOptionsEList("-sl", "Seeverity level", "",
148  severityStrings.data(), SeverityLevel::error + 1,
149  severityStrings[sev_level], &sev_level, PETSC_NULL);
150 
151  CHKERR PetscOptionsBool("-scope", "Log scope", "", log_scope, &log_scope,
152  NULL);
153 
154  CHKERR PetscOptionsBool("-quiet", "Quiet log attributes", "", log_quiet,
155  &log_quiet, NULL);
156 
157  CHKERR PetscOptionsBool("-no_color", "Terminal with no colors", "",
158  log_no_colors, &log_no_colors, NULL);
159  CHKERR PetscOptionsBool("-nc", "Terminal with no colors", "", log_no_colors,
160  &log_no_colors, NULL);
161 
162  CHKERR PetscOptionsBool("-time", "Log time", "",
163  log_time, &log_time, NULL);
164 
165  ierr = PetscOptionsEnd();
166  CHKERRG(ierr);
167 
168  logging::core::get()->set_filter(MoFEM::LogKeywords::severity >= sev_level);
169 
170  if (log_scope)
171  logging::core::get()->add_global_attribute("Scope", attrs::named_scope());
172 
173  if (log_quiet)
175 
176  if (log_no_colors)
178 
179  if (log_time)
181 
183 }
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:496
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
#define CHKERR
Inline error check.
Definition: definitions.h:548
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:87
static constexpr std::array< char *const, error+1 > severityStrings
Definition: LogManager.hpp:45

◆ getStrmSelf()

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

Get the strm self object.

Returns
boost::shared_ptr<std::ostream>
Examples
add_cubit_meshsets.cpp, continuity_check_on_skeleton_3d.cpp, continuity_check_on_skeleton_with_simple_2d_for_h1.cpp, continuity_check_on_skeleton_with_simple_2d_for_hcurl.cpp, log.cpp, and matrix_function.cpp.

Definition at line 319 of file LogManager.cpp.

319  {
320  return internalDataPtr->getStrmSelf();
321 }

◆ getStrmSync()

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

Get the strm sync object.

Returns
boost::shared_ptr<std::ostream>
Examples
ep.cpp.

Definition at line 327 of file LogManager.cpp.

327  {
328  return internalDataPtr->getStrmSync();
329 }

◆ getStrmWorld()

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

◆ 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 435 of file LogManager.cpp.

435  {
436  std::array<char, 1024> buf;
437  vsprintf(buf.data(), fmt, args);
438  return std::string(buf.data());
439 }

◆ 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 381 of file LogManager.cpp.

382  {
384  if (fd != stdout && fd != stderr && fd != dummy_mofem_fd) {
385  CHKERR PetscVFPrintfDefault(fd, format, Argp);
386 
387  } else {
388 
389  std::array<char, 1024> buff;
390  size_t length;
391  CHKERR PetscVSNPrintf(buff.data(), 1024, format, &length, Argp);
392 
393  auto get_str = [&buff]() {
394  std::string str;
395  if (!petscStringCache.empty())
396  str = petscStringCache + std::string(buff.data());
397  else
398  str = std::string(buff.data());
399  return str;
400  };
401  const auto str = get_str();
402 
403  if (!str.empty()) {
404  if (fd != dummy_mofem_fd) {
405 
407  MoFEM::LogManager::SeverityLevel::inform;
408  if (str.find("WARNING") != std::string::npos)
409  sev = MoFEM::LogManager::SeverityLevel::warning;
410 
411  std::istringstream is(str);
412  std::string line;
413  std::vector<std::string> log_list;
414 
415  while (getline(is, line, '\n'))
416  log_list.push_back(line);
417 
418  if (str.back() != '\n') {
419  petscStringCache = log_list.back();
420  log_list.pop_back();
421  } else
422  petscStringCache.clear();
423 
424  for(auto &line : log_list)
425  MOFEM_LOG("PETSC", sev) << line;
426 
427  } else {
428  std::clog << str;
429  }
430  }
431  }
433 }
PetscErrorCode PetscVFPrintfDefault(FILE *fd, const char *format, va_list Argp)
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:311
SeverityLevel
Severity levels.
Definition: LogManager.hpp:43
static std::string petscStringCache
Definition: LogManager.hpp:242
static FILE * dummy_mofem_fd
Dummy file pointer (DO NOT USE)
Definition: LogManager.hpp:194

◆ query_interface()

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

Implements MoFEM::UnknownInterface.

Definition at line 126 of file LogManager.cpp.

127  {
129  *iface = const_cast<LogManager *>(this);
131 }
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:453
LogManager(const MoFEM::Core &core)
Definition: LogManager.cpp:122

◆ recordFormatterDefault()

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

Default record formatter.

Parameters
rec
strm

Definition at line 185 of file LogManager.cpp.

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

Member Data Documentation

◆ cOre

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

Definition at line 237 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 194 of file LogManager.hpp.

◆ internalDataPtr

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

Definition at line 240 of file LogManager.hpp.

◆ petscStringCache

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

Definition at line 242 of file LogManager.hpp.

◆ severityStrings

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

Definition at line 45 of file LogManager.hpp.


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