17#include <boost/date_time/posix_time/posix_time.hpp>
23constexpr std::array<char *const, LogManager::SeverityLevel::error + 1>
35 :
public boost::enable_shared_from_this<LogManager::InternalData> {
39 if (!this->str().empty()) {
51 if (!this->str().empty()) {
66 if (!this->str().empty()) {
84 return (
c == traits_type::eof()) ?
'\0' :
c;
112 return boost::shared_ptr<std::ostream>(shared_from_this(), &
strmSelf);
115 return boost::shared_ptr<std::ostream>(shared_from_this(), &
strmWorld);
118 return boost::shared_ptr<std::ostream>(shared_from_this(), &
strmSync);
121 return boost::shared_ptr<std::ostream>(shared_from_this(), &
nullSelf);
136std::map<std::string, LogManager::LoggerType>
142 : cOre(const_cast<
MoFEM::
Core &>(core)) {}
155 PetscBool log_scope = PETSC_FALSE;
156 PetscBool log_quiet = PETSC_FALSE;
157 PetscBool log_no_colors = PETSC_FALSE;
158 PetscBool log_time = PETSC_FALSE;
160 CHKERR PetscOptionsBegin(PETSC_COMM_WORLD,
"log_",
161 "Logging interface options",
"none");
163 CHKERR PetscOptionsEList(
"-severity_level",
"Severity level",
"",
166 CHKERR PetscOptionsEList(
"-sl",
"Severity level",
"",
170 CHKERR PetscOptionsBool(
"-scope",
"Log scope",
"", log_scope, &log_scope,
173 CHKERR PetscOptionsBool(
"-quiet",
"Quiet log attributes",
"", log_quiet,
176 CHKERR PetscOptionsBool(
"-no_color",
"Terminal with no colors",
"",
177 log_no_colors, &log_no_colors, NULL);
178 CHKERR PetscOptionsBool(
"-nc",
"Terminal with no colors",
"", log_no_colors,
179 &log_no_colors, NULL);
181 CHKERR PetscOptionsBool(
"-time",
"Log time",
"",
182 log_time, &log_time, NULL);
184 ierr = PetscOptionsEnd();
187 logging::core::get()->set_filter(MoFEM::LogKeywords::severity >= sev_level);
190 logging::core::get()->add_global_attribute(
"Scope", attrs::named_scope());
205 logging::formatting_ostream &strm) {
209 auto sev = rec[severity];
210 auto p = rec[proc_attr];
211 auto l = rec[line_id];
213 auto tg = rec[tag_attr];
214 auto tl = rec[timeline];
216 auto set_color = [&](
const auto str) {
217#if defined(PETSC_HAVE_UNISTD_H) && defined(PETSC_USE_ISATTY)
225 auto local_time = boost::posix_time::second_clock::local_time();
226 strm <<
"(Local time ";
227 strm << local_time.date().year() <<
"-" << local_time.date().month()
228 <<
"-" << local_time.date().day() <<
" "
229 << local_time.time_of_day().hours() <<
":"
230 << local_time.time_of_day().minutes() <<
":"
231 << local_time.time_of_day().seconds();
238 set_color(
"\033[32m");
240 set_color(
"\033[0m");
246 set_color(
"\033[1m");
248 set_color(
"\033[31m");
251 set_color(
"\033[34m");
254 set_color(
"\033[35m");
257 set_color(
"\033[36m");
263 set_color(
"\033[0m");
266 strm << std::hex << std::setw(8) << std::setfill(
'0') <<
l.get()
267 << std::dec << std::setfill(
' ') <<
": ";
270 for (::boost::log::attributes::named_scope_list::const_iterator iter =
272 iter != s->end(); ++iter) {
273 const auto path = std::string(iter->file_name.data());
274 const auto file = path.substr(path.find_last_of(
"/\\") + 1);
275 strm <<
"(" << file <<
":" << iter->line <<
">" << iter->scope_name
283 set_color(
"\033[1m");
284 strm <<
"[" << tg.get() <<
"] ";
285 set_color(
"\033[0m");
289 strm <<
"[" << tl.get() <<
"] ";
292 auto msg = rec[logging::expressions::smessage];
297boost::shared_ptr<LogManager::SinkType>
299 std::string comm_filter) {
301 auto backend = boost::make_shared<sinks::text_ostream_backend>();
303 backend->add_stream(stream_ptr);
304 backend->auto_flush(
true);
306 auto sink = boost::make_shared<SinkType>(backend);
307 sink->set_filter((expr::has_attr(channel) && channel == comm_filter));
317 auto core_log = logging::core::get();
318 core_log->remove_all_sinks();
320 boost::shared_ptr<std::ostream>(&std::clog, boost::null_deleter()),
336 MPI_Comm_rank(comm, &rank);
337 core_log->add_global_attribute(
"Proc", attrs::constant<unsigned int>(rank));
367 lg.add_attribute(
"LineID", attrs::counter<unsigned int>(1));
370 lg.add_attribute(
"Scope", attrs::named_scope());
382 lg.add_attribute(
"Tag", attrs::constant<std::string>(tag));
386 getLog(channel).add_attribute(
"Tag", attrs::constant<std::string>(tag));
391 LoggerType(boost::log::keywords::channel = channel);
414 std::array<char, 1024> buff;
416 CHKERR PetscVSNPrintf(buff.data(), 1024, format, &length, Argp);
418 auto get_str = [&buff]() {
423 str = std::string(buff.data());
426 const auto str = get_str();
433 if (str.find(
"WARNING") != std::string::npos)
436 std::istringstream is(str);
438 std::vector<std::string> log_list;
440 while (getline(is, line,
'\n'))
441 log_list.push_back(line);
443 if (str.back() !=
'\n') {
449 for(
auto &line : log_list)
461 std::array<char, 1024> buf;
462 vsprintf(buf.data(), fmt, args);
463 return std::string(buf.data());
PetscErrorCode PetscVFPrintfDefault(FILE *fd, const char *format, va_list Argp)
virtual int overflow(int c)
#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.
const double c
speed of light (cm/ns)
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()
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.
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