17#include <boost/date_time/posix_time/posix_time.hpp>
32 :
public boost::enable_shared_from_this<LogManager::InternalData> {
36 if (!this->str().empty()) {
48 if (!this->str().empty()) {
63 if (!this->str().empty()) {
64 PetscSynchronizedFPrintf(
cOmm,
fD,
"%s", this->str().c_str());
81 return (
c == traits_type::eof()) ?
'\0' :
c;
109 return boost::shared_ptr<std::ostream>(shared_from_this(), &
strmSelf);
112 return boost::shared_ptr<std::ostream>(shared_from_this(), &
strmWorld);
115 return boost::shared_ptr<std::ostream>(shared_from_this(), &
strmSync);
118 return boost::shared_ptr<std::ostream>(shared_from_this(), &
nullSelf);
133std::map<std::string, LogManager::LoggerType>
139 : cOre(const_cast<
MoFEM::
Core &>(core)) {}
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;
157 PetscOptionsBegin(PETSC_COMM_WORLD,
"log_",
"Logging interface options",
160 CHKERR PetscOptionsEList(
"-severity_level",
"Severity level",
"",
166 &sev_level, PETSC_NULLPTR);
168 CHKERR PetscOptionsBool(
"-scope",
"Log scope",
"", log_scope, &log_scope,
171 CHKERR PetscOptionsBool(
"-quiet",
"Quiet log attributes",
"", log_quiet,
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);
179 CHKERR PetscOptionsBool(
"-time",
"Log time",
"", log_time, &log_time, NULL);
183 logging::core::get()->set_filter(MoFEM::LogKeywords::severity >= sev_level);
186 logging::core::get()->add_global_attribute(
"Scope", attrs::named_scope());
201 logging::formatting_ostream &strm) {
205 auto sev = rec[severity];
206 auto p = rec[proc_attr];
207 auto l = rec[line_id];
209 auto tg = rec[tag_attr];
210 auto tl = rec[timeline];
212 auto set_color = [&](
const auto str) {
213#if defined(PETSC_HAVE_UNISTD_H) && defined(PETSC_USE_ISATTY)
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();
233 set_color(
"\033[32m");
235 set_color(
"\033[0m");
241 set_color(
"\033[1m");
243 set_color(
"\033[31m");
246 set_color(
"\033[34m");
249 set_color(
"\033[35m");
252 set_color(
"\033[36m");
258 set_color(
"\033[0m");
261 strm << std::hex << std::setw(8) << std::setfill(
'0') <<
l.get()
262 << std::dec << std::setfill(
' ') <<
": ";
265 for (::boost::log::attributes::named_scope_list::const_iterator iter =
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
278 set_color(
"\033[1m");
279 strm <<
"[" << tg.get() <<
"] ";
280 set_color(
"\033[0m");
284 strm <<
"[" << tl.get() <<
"] ";
287 auto msg = rec[logging::expressions::smessage];
292boost::shared_ptr<LogManager::SinkType>
294 std::string comm_filter) {
296 auto backend = boost::make_shared<sinks::text_ostream_backend>();
298 backend->add_stream(stream_ptr);
299 backend->auto_flush(
true);
301 auto sink = boost::make_shared<SinkType>(backend);
302 sink->set_filter((expr::has_attr(channel) && channel == comm_filter));
312 auto core_log = logging::core::get();
313 core_log->remove_all_sinks();
315 boost::shared_ptr<std::ostream>(&std::clog, boost::null_deleter()),
331 MPI_Comm_rank(comm, &rank);
332 core_log->add_global_attribute(
"Proc", attrs::constant<unsigned int>(rank));
354 boost::make_shared<InternalData::SynchronizedStreamBuf>(comm, fd);
355 return boost::shared_ptr<std::ostream>(buff_ptr,
356 new std::ostream(buff_ptr.get()));
370 lg.add_attribute(
"LineID", attrs::counter<unsigned int>(1));
373 lg.add_attribute(
"Scope", attrs::named_scope());
385 lg.add_attribute(
"Tag", attrs::constant<std::string>(tag));
389 getLog(channel).add_attribute(
"Tag", attrs::constant<std::string>(tag));
394 LoggerType(boost::log::keywords::channel = channel);
402 "Channel <" + channel +
"> not found");
422 std::array<char, 1024> buff;
424 CHKERR PetscVSNPrintf(buff.data(), 1024, format, &length, Argp);
426 auto get_str = [&buff]() {
431 str = std::string(buff.data());
434 const auto str = get_str();
441 if (str.find(
"WARNING") != std::string::npos)
444 std::istringstream is(str);
446 std::vector<std::string> log_list;
448 while (getline(is, line,
'\n'))
449 log_list.push_back(line);
451 if (str.back() !=
'\n') {
457 for (
auto &line : log_list)
469 std::array<char, 1024> buf;
470 vsprintf(buf.data(), fmt, args);
471 return std::string(buf.data());
PetscErrorCode PetscVFPrintfDefault(FILE *fd, const char *format, va_list Argp)
virtual int overflow(int c)
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
SeverityLevel
Severity levels.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
static void addTag(LogManager::LoggerType &lg, const std::string tag)
Add tag to logger.
static void addAttributes(LogManager::LoggerType &lg, const int bit=0)
Add attributes to logger.
static LoggerType & getLog(const std::string channel)
Get logger by channel.
const double c
speed of light (cm/ns)
FTensor::Index< 'l', 3 > l
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
std::ostream & operator<<(std::ostream &os, const EntitiesFieldData::EntData &e)
SynchronizedStreamBuf(MPI_Comm comm, FILE *fd)
WorldStreamBuf(MPI_Comm comm)
boost::shared_ptr< std::ostream > getStrmWorld()
boost::shared_ptr< std::ostream > getStrmNull()
SynchronizedStreamBuf syncBuf
virtual ~InternalData()=default
boost::shared_ptr< std::ostream > getStrmSync()
static std::map< std::string, LoggerType > logChannels
boost::shared_ptr< std::ostream > getStrmSelf()
InternalData(MPI_Comm comm)
Log manager is used to build and partition problems.
static boost::shared_ptr< std::ostream > getStrmNull()
Get the strm null object.
boost::log::sources::severity_channel_logger< SeverityLevel, std::string > LoggerType
Definition of the channel logger.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
LogManager(const MoFEM::Core &core)
static MoFEMErrorCode getOptions()
Get logger option.
static std::string getCLikeFormatedString(const char *fmt,...)
Converts formatted output to string.
static void createDefaultSinks(MPI_Comm comm)
Create default sinks.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
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 boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
static void recordFormatterDefault(logging::record_view const &rec, logging::formatting_ostream &strm)
Default record formatter.
static bool checkIfChannelExist(const std::string channel)
Check if channel exist.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
static std::string petscStringCache
static FILE * dummy_mofem_fd
Dummy file pointer (DO NOT USE)
static boost::shared_ptr< InternalData > internalDataPtr
static constexpr std::array< char *const, error+1 > severityStrings
base class for all interface classes