v0.9.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | 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 (const MOFEMuuid &uuid, UnknownInterface **iface) const
 
 LogManager (const MoFEM::Core &core)
 
virtual ~LogManager ()=default
 
MoFEMErrorCode getSubInterfaceOptions ()
 Get the Interface Options. More...
 
MoFEMErrorCode getOptions ()
 Get options from command line. More...
 
- Public Member Functions inherited from MoFEM::UnknownInterface
template<class IFACE >
MoFEMErrorCode registerInterface (const MOFEMuuid &uuid, bool error_if_registration_failed=true)
 Register interface. More...
 
template<class IFACE , bool VERIFY = false>
MoFEMErrorCode getInterface (const MOFEMuuid &uuid, IFACE *&iface) const
 Get interface by uuid and return reference to pointer of 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
 
virtual MoFEMErrorCode getLibVersion (Version &version) const
 Get library version. More...
 
virtual const MoFEMErrorCode getFileVersion (moab::Interface &moab, Version &version) const
 Get database major version. More...
 
virtual MoFEMErrorCode getInterfaceVersion (Version &version) const
 Get database major version. More...
 
template<>
MoFEMErrorCode getInterface (const MOFEMuuid &uuid, UnknownInterface *&iface) const
 

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 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< SinkTypecreateSink (boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
 
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 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 Member Functions

MoFEMErrorCode setUpLog ()
 

Private Attributes

MoFEM::CorecOre
 
boost::shared_ptr< InternalDatainternalDataPtr
 

Additional Inherited Members

- Protected Member Functions inherited from MoFEM::UnknownInterface
boost::typeindex::type_index getClassIdx (const MOFEMuuid &uid) const
 Get type name for interface Id. More...
 
MOFEMuuid getUId (const boost::typeindex::type_index &class_idx) const
 Get interface Id for class name. More...
 

Detailed Description

Log manager is used to build and partition problems.

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

◆ SinkType

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

Definition at line 92 of file LogManager.hpp.

Constructor & Destructor Documentation

◆ LogManager()

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

Definition at line 112 of file LogManager.cpp.

113  : cOre(const_cast<MoFEM::Core &>(core)),
115  new InternalData(static_cast<MoFEM::Interface &>(cOre).get_comm())) {}
boost::shared_ptr< InternalData > internalDataPtr
Definition: LogManager.hpp:219
MoFEM::Core & cOre
Definition: LogManager.hpp:217

◆ ~LogManager()

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

Member Function Documentation

◆ createSink()

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

Definition at line 238 of file LogManager.cpp.

239  {
240 
241  auto backend = boost::make_shared<sinks::text_ostream_backend>();
242  if (stream_ptr)
243  backend->add_stream(stream_ptr);
244  backend->auto_flush(true);
245 
246  auto sink = boost::make_shared<SinkType>(backend);
247  sink->set_filter((expr::has_attr(channel) && channel == comm_filter));
248  sink->set_formatter(&recordFormatterDefault);
249 
250  return sink;
251 }
static void recordFormatterDefault(logging::record_view const &rec, logging::formatting_ostream &strm)
Default record formatter.
Definition: LogManager.cpp:166

◆ getCLikeFormatedString()

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

Converts formatted output to string.

Parameters
fmt
args
Returns
std::string

Definition at line 349 of file LogManager.cpp.

349  {
350  va_list args;
351  va_start(args, fmt);
352  auto str = getVLikeFormatedString(fmt, args);
353  va_end(args);
354  return str;
355 }
static std::string getVLikeFormatedString(const char *fmt, va_list args)
Converts formatted output to string.
Definition: LogManager.cpp:343

◆ getOptions()

MoFEMErrorCode MoFEM::LogManager::getOptions ( )

Get options from command line.

Returns
error code

Definition at line 131 of file LogManager.cpp.

131  {
133  PetscInt sev_level = SeverityLevel::inform;
134  PetscBool log_scope = PETSC_FALSE;
135  PetscBool log_quiet = PETSC_FALSE;
136 
137  CHKERR PetscOptionsBegin(PETSC_COMM_WORLD, "log_",
138  "Logging interface options", "none");
139 
140  CHKERR PetscOptionsEList("-severity_level", "Scope level", "",
142  severityStrings[sev_level], &sev_level, PETSC_NULL);
143 
144  CHKERR PetscOptionsBool("-scope", "Log scope", "", log_scope, &log_scope,
145  NULL);
146 
147  CHKERR PetscOptionsBool("-quiet", "Quiet log attributes", "", log_quiet,
148  &log_quiet, NULL);
149 
150  ierr = PetscOptionsEnd();
151  CHKERRG(ierr);
152 
153  CHKERR setUpLog();
154 
155  logging::core::get()->set_filter(MoFEM::LogKeywords::severity >= sev_level);
156 
157  if (log_scope)
158  logging::core::get()->add_global_attribute("Scope", attrs::named_scope());
159 
160  if(log_quiet)
162 
164 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:550
static constexpr std::array< char *const, error+1 > severityStrings
Definition: LogManager.hpp:61
static moab::Error error
#define CHKERR
Inline error check.
Definition: definitions.h:602
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413
MoFEMErrorCode setUpLog()
Definition: LogManager.cpp:256

◆ getSubInterfaceOptions()

MoFEMErrorCode MoFEM::LogManager::getSubInterfaceOptions ( )

Get the Interface Options.

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

Returns
MoFEMErrorCode

Definition at line 129 of file LogManager.cpp.

129 { return getOptions(); }
MoFEMErrorCode getOptions()
Get options from command line.
Definition: LogManager.cpp:131

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

343  {
344  std::array<char, 1024> buf;
345  vsprintf(buf.data(), fmt, args);
346  return std::string(buf.data());
347 }

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

309  {
310  PetscErrorCode ierr;
311  PetscFunctionBegin;
312  if (fd != stdout && fd != stderr && fd != dummy_mofem_fd) {
313  ierr = PetscVFPrintfDefault(fd, format, Argp);
314  CHKERR(ierr);
315 
316  } else {
317  std::array<char, 1024> buff;
318  size_t length;
319  ierr = PetscVSNPrintf(buff.data(), 1024, format, &length, Argp);
320  CHKERRQ(ierr);
321 
322  auto remove_line_break = [](auto &&msg) {
323  if (!msg.empty() && msg.back() == '\n')
324  msg = std::string_view(msg.data(), msg.size() - 1);
325  return msg;
326  };
327 
328  std::ostringstream ss;
329 
330  const std::string str(buff.data());
331  if (!str.empty()) {
332  if (fd != dummy_mofem_fd) {
333  MOFEM_LOG("PETSC", MoFEM::LogManager::SeverityLevel::inform)
334  << ss.str() << remove_line_break(std::string(buff.data()));
335  } else {
336  std::clog << ss.str() << std::string(buff.data());
337  }
338  }
339  }
340  PetscFunctionReturn(0);
341 }
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:290
PetscErrorCode PetscVFPrintfDefault(FILE *fd, const char *format, va_list Argp)
static FILE * dummy_mofem_fd
Dummy file pointer (DO NOT USE)
Definition: LogManager.hpp:174
CHKERRQ(ierr)
#define CHKERR
Inline error check.
Definition: definitions.h:602

◆ query_interface()

MoFEMErrorCode MoFEM::LogManager::query_interface ( const MOFEMuuid uuid,
UnknownInterface **  iface 
) const
virtual

Implements MoFEM::UnknownInterface.

Definition at line 117 of file LogManager.cpp.

118  {
120  *iface = NULL;
121  if (uuid == IDD_MOFEMLogManager) {
122  *iface = const_cast<LogManager *>(this);
124  }
125  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "unknown interface");
127 }
static const MOFEMuuid IDD_MOFEMLogManager
Definition: LogManager.hpp:44
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514

◆ recordFormatterDefault()

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

Default record formatter.

Parameters
rec
strm

Definition at line 166 of file LogManager.cpp.

167  {
168 
169 
171 
172  auto sev = rec[severity];
173  auto p = rec[proc_attr];
174  auto l = rec[line_id];
175  auto s = rec[scope];
176  auto tg = rec[tag_attr];
177  auto tl = rec[timeline];
178 
179  auto set_color = [&](const auto str) {
180 #if defined(PETSC_HAVE_UNISTD_H) && defined(PETSC_USE_ISATTY)
181  if (isatty(fileno(stdout)))
182  strm << str;
183 #endif
184  };
185 
186  if (!p.empty()) {
187  strm << "[";
188  set_color("\033[32m");
189  strm << p;
190  set_color("\033[0m");
191  strm << "] ";
192  }
193 
194  if (sev > SeverityLevel::inform) {
195  set_color("\033[31m");
196  if (sev > SeverityLevel::warning)
197  set_color("\033[1m");
198  } else
199  set_color("\033[34m");
200 
201  strm << sev;
202 
203  set_color("\033[0m");
204 
205  if (!l.empty())
206  strm << std::hex << std::setw(8) << std::setfill('0') << l.get()
207  << std::dec << std::setfill(' ') << ": ";
208 
209  if (!s.empty()) {
210  for (::boost::log::attributes::named_scope_list::const_iterator iter =
211  s->begin();
212  iter != s->end(); ++iter) {
213  const auto path = std::string(iter->file_name.data());
214  const auto file = path.substr(path.find_last_of("/\\") + 1);
215  strm << "(" << file << ":" << iter->line << ">" << iter->scope_name
216  << ")";
217  }
218  strm << " ";
219  }
220 
221  if (!tg.empty()) {
222 
223  set_color("\033[1m");
224  strm << "[" << tg.get() << "] ";
225  set_color("\033[0m");
226  }
227 
228  if (!tl.empty())
229  strm << "[" << tl.get() << "] ";
230  }
231 
232  auto msg = rec[logging::expressions::smessage];
233 
234  strm << msg;
235 }
FTensor::Index< 'l', 2 > l
Definition: ContactOps.hpp:29

◆ setUpLog()

MoFEMErrorCode MoFEM::LogManager::setUpLog ( )
private

Definition at line 256 of file LogManager.cpp.

256  {
257  MoFEM::Interface &m_field = cOre;
259 
260  auto core_log = logging::core::get();
261  core_log->add_sink(createSink(internalDataPtr->getStrmSelf(), "SELF"));
262  core_log->add_sink(createSink(internalDataPtr->getStrmWorld(), "WORLD"));
263  core_log->add_sink(createSink(internalDataPtr->getStrmSync(), "SYNC"));
264 
266 }
Deprecated interface functions.
boost::shared_ptr< InternalData > internalDataPtr
Definition: LogManager.hpp:219
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Definition: LogManager.cpp:238
MoFEM::Core & cOre
Definition: LogManager.hpp:217
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413

Member Data Documentation

◆ cOre

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

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

◆ internalDataPtr

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

Definition at line 219 of file LogManager.hpp.

◆ severityStrings

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

Definition at line 61 of file LogManager.hpp.


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