39 #ifdef __PARALLEL_MODE 44 #if defined ( __GNUC__ ) && defined ( HAVE_EXECINFO_H ) 51 static inline void print_stacktrace(FILE *out = stderr,
unsigned int max_frames = 63)
54 fprintf(out,
"stack trace:\n");
57 void *addrlist [ max_frames + 1 ];
60 addrlen = backtrace( addrlist,
sizeof( addrlist ) /
sizeof(
void * ) );
62 fprintf(out,
" <empty, possibly corrupt>\n");
69 symbollist = backtrace_symbols(addrlist, addrlen);
71 size_t funcnamesize = 256;
72 char *funcname = (
char * ) malloc(funcnamesize);
76 for (
int i = 2; i < addrlen; i++ ) {
77 char *begin_name = 0, *begin_offset = 0, *end_offset = 0;
81 for (
char *p = symbollist [ i ]; * p; ++p ) {
84 }
else if ( * p ==
'+' ) {
86 }
else if ( * p ==
')' && begin_offset ) {
92 if ( begin_name && begin_offset && end_offset &&
93 begin_name < begin_offset ) {
94 * begin_name++ =
'\0';
95 * begin_offset++ =
'\0';
103 char *ret = abi :: __cxa_demangle(begin_name,
104 funcname, & funcnamesize, & status);
107 fprintf(out,
" %s : %s+%s\n",
108 symbollist [ i ], funcname, begin_offset);
112 fprintf(out,
" %s : %s()+%s\n",
113 symbollist [ i ], begin_name, begin_offset);
117 fprintf(out,
" %s\n", symbollist [ i ]);
127 fprintf(out,
"No backtrace available\n");
132 #define LOG_ERR_HEADER "_______________________________________________________" 133 #define LOG_ERR_TAIL "_______________________________________________________\a\n" 146 #ifdef __PARALLEL_MODE
166 stream = freopen(fname.c_str(),
"a", this->
logStream);
168 stream = fopen(fname.c_str(),
"a");
171 if ( stream == NULL ) {
185 stream = freopen(fname.c_str(),
"a", this->
errStream);
187 stream = fopen(fname.c_str(),
"a");
190 if ( stream == NULL ) {
206 if ( stream == NULL ) {
207 OOFEM_ERROR(
"Logger::appendLogTo : null stream given" );
222 if ( stream == NULL ) {
223 OOFEM_ERROR(
"Logger::appendLogTo : null stream given" );
238 #ifdef __PARALLEL_MODE 239 MPI_Comm_rank(this->
comm, & rank);
257 va_start(args, format);
258 vfprintf(stream, format, args);
285 fprintf(stream,
"In %s:\n", _func );
288 va_start(args, format);
289 vfprintf(stream, format, args);
323 #ifdef __PARALLEL_MODE 336 #ifdef __PARALLEL_MODE 337 MPI_Comm_rank(this->
comm, & rank);
341 #ifdef __PARALLEL_MODE 342 MPI_Reduce(&
numberOfErr, & totalNumberOfErr, 1, MPI_INT, MPI_SUM, 0, this->
comm);
343 MPI_Reduce(&
numberOfWrn, & totalNumberOfWrn, 1, MPI_INT, MPI_SUM, 0, this->
comm);
347 fprintf(
logStream,
"Total %d error(s) and %d warning(s) reported\n", totalNumberOfErr, totalNumberOfWrn);
void setLogLevel(logLevelType level)
Sets log level to given one. Only log messages with level less or equal given threshold will be print...
FILE * logStream
Stream used for logging.
bool closeFlag
flag indicating whether to close mylogStream.
void writeELogMsg(logLevelType level, const char *_func, const char *_file, int _line, const char *format,...)
Writes extended log message with file and line info.
void writeLogMsg(logLevelType level, const char *format,...)
Writes the normal log message.
void printStatistics()
Prints number of errors and warning logged.
MPI_Comm comm
Parallell comm.
Logger oofem_logger(Logger::LOG_LEVEL_INFO)
Logger(logLevelType level)
const char * giveLevelName(logLevelType l) const
void appendErrorTo(const std::string &fname)
Redirects error output to given file name (with path).
void appendLogTo(const std::string &fname)
Redirects log output to given file name (with path).
static void print_stacktrace(FILE *out=stderr, unsigned int max_frames=63)
logLevelType logLevel
Current log level, messages with higher level are not reported.
logLevelType
Type defining basic log levels.
int numberOfWrn
Counter of all warning and error messages.
the oofem namespace is to define a context or scope in which all oofem names are defined.
#define OOFEM_WARNING(...)
void setComm(MPI_Comm comm)
Parallell comm.