17#include <boost/date_time/posix_time/posix_time.hpp>
25constexpr std::array<char *const, LogManager::SeverityLevel::error + 1>
37 :
public boost::enable_shared_from_this<LogManager::InternalData> {
41 if (!this->str().empty()) {
53 if (!this->str().empty()) {
68 if (!this->str().empty()) {
96 return boost::shared_ptr<std::ostream>(shared_from_this(), &
strmSelf);
99 return boost::shared_ptr<std::ostream>(shared_from_this(), &
strmWorld);
102 return boost::shared_ptr<std::ostream>(shared_from_this(), &
strmSync);
117std::map<std::string, LogManager::LoggerType>
123 : cOre(const_cast<
MoFEM::
Core &>(core)) {}
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;
141 CHKERR PetscOptionsBegin(PETSC_COMM_WORLD,
"log_",
142 "Logging interface options",
"none");
144 CHKERR PetscOptionsEList(
"-severity_level",
"Severity level",
"",
147 CHKERR PetscOptionsEList(
"-sl",
"Seeverity level",
"",
151 CHKERR PetscOptionsBool(
"-scope",
"Log scope",
"", log_scope, &log_scope,
154 CHKERR PetscOptionsBool(
"-quiet",
"Quiet log attributes",
"", log_quiet,
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);
162 CHKERR PetscOptionsBool(
"-time",
"Log time",
"",
163 log_time, &log_time, NULL);
165 ierr = PetscOptionsEnd();
168 logging::core::get()->set_filter(MoFEM::LogKeywords::severity >= sev_level);
171 logging::core::get()->add_global_attribute(
"Scope", attrs::named_scope());
186 logging::formatting_ostream &strm) {
190 auto sev = rec[severity];
191 auto p = rec[proc_attr];
192 auto l = rec[line_id];
194 auto tg = rec[tag_attr];
195 auto tl = rec[timeline];
197 auto set_color = [&](
const auto str) {
198#if defined(PETSC_HAVE_UNISTD_H) && defined(PETSC_USE_ISATTY)
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();
219 set_color(
"\033[32m");
221 set_color(
"\033[0m");
227 set_color(
"\033[1m");
229 set_color(
"\033[31m");
232 set_color(
"\033[34m");
235 set_color(
"\033[35m");
238 set_color(
"\033[36m");
244 set_color(
"\033[0m");
247 strm << std::hex << std::setw(8) << std::setfill(
'0') <<
l.get()
248 << std::dec << std::setfill(
' ') <<
": ";
251 for (::boost::log::attributes::named_scope_list::const_iterator iter =
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
264 set_color(
"\033[1m");
265 strm <<
"[" << tg.get() <<
"] ";
266 set_color(
"\033[0m");
270 strm <<
"[" << tl.get() <<
"] ";
273 auto msg = rec[logging::expressions::smessage];
278boost::shared_ptr<LogManager::SinkType>
280 std::string comm_filter) {
282 auto backend = boost::make_shared<sinks::text_ostream_backend>();
284 backend->add_stream(stream_ptr);
285 backend->auto_flush(
true);
287 auto sink = boost::make_shared<SinkType>(backend);
288 sink->set_filter((expr::has_attr(channel) && channel == comm_filter));
298 auto core_log = logging::core::get();
299 core_log->remove_all_sinks();
301 boost::shared_ptr<std::ostream>(&std::clog, boost::null_deleter()),
315 MPI_Comm_rank(comm, &rank);
316 core_log->add_global_attribute(
"Proc", attrs::constant<unsigned int>(rank));
342 lg.add_attribute(
"LineID", attrs::counter<unsigned int>(1));
345 lg.add_attribute(
"Scope", attrs::named_scope());
357 lg.add_attribute(
"Tag", attrs::constant<std::string>(tag));
361 getLog(channel).add_attribute(
"Tag", attrs::constant<std::string>(tag));
366 LoggerType(boost::log::keywords::channel = channel);
389 std::array<char, 1024> buff;
391 CHKERR PetscVSNPrintf(buff.data(), 1024, format, &length, Argp);
393 auto get_str = [&buff]() {
398 str = std::string(buff.data());
401 const auto str = get_str();
408 if (str.find(
"WARNING") != std::string::npos)
411 std::istringstream is(str);
413 std::vector<std::string> log_list;
415 while (getline(is, line,
'\n'))
416 log_list.push_back(line);
418 if (str.back() !=
'\n') {
424 for(
auto &line : log_list)
436 std::array<char, 1024> buf;
437 vsprintf(buf.data(), fmt, args);
438 return std::string(buf.data());
static int dummy_file_ptr
PetscErrorCode PetscVFPrintfDefault(FILE *fd, const char *format, va_list Argp)
#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 ...
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
#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.
FTensor::Index< 'l', 3 > l
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
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)
WorldStreamBuf(MPI_Comm comm)
boost::shared_ptr< std::ostream > getStrmWorld()
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 constexpr std::array< char *const, error+1 > severityStrings
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.
boost::log::sources::severity_channel_logger< SeverityLevel, std::string > LoggerType
Definition of the channel logger.
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
base class for all interface classes