OOFEM 3.0
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35#ifndef logger_h
36#define logger_h
37
38#include "oofemenv.h"
39//#include "util.h"
40
41#include <cstdio>
42#include <string>
43#ifdef __MPI_PARALLEL_MODE
44#include <mpi.h>
45#endif
46
47// MSVC doesn't properly implement C99. (might need to wrap __func__ behind a macro to support all platforms correctly(?))
48#ifdef _MSC_VER
49# define __func__ __FUNCTION__
50#endif
51
52namespace oofem {
58{
59public:
69protected:
78#ifdef __MPI_PARALLEL_MODE
80 MPI_Comm comm;
81#endif
82public:
83 Logger(logLevelType level);
84 ~Logger();
86 void appendLogTo(const std :: string &fname);
88 void appendErrorTo(const std :: string &fname);
90 void appendLogTo(FILE* stream);
92 void appendErrorTo(FILE* stream);
93#ifdef __MPI_PARALLEL_MODE
95 void setComm(MPI_Comm comm);
96#endif
97
99 void writeLogMsg(logLevelType level, const char *format, ...)
100 #if defined(__GNUC__) || defined (__clang)
101 __attribute__((format(printf, 3, 4)))
102 #endif
103 ;
105 void writeELogMsg(logLevelType level, const char *_func, const char *_file, int _line, const char *format, ...)
106 #if defined(__GNUC__) || defined (__clang)
107 __attribute__((format(printf, 6, 7)))
108 #endif
109 ;
111 void flush() { fflush(logStream); fflush(errStream); }
112
114 void setLogLevel(logLevelType level) { logLevel = level; }
116 void setLogLevel(int level);
120 void printStatistics();
122 void getNumberOfWarningsAndErrors(int& nwrns, int &nerrs) {
123 nwrns = numberOfWrn;
124 nerrs = numberOfErr;
125 }
126
127protected:
128 const char *giveLevelName(logLevelType l) const;
129};
130
132
137#define OOFEM_LOG_FATAL(...) oofem_logger.writeELogMsg(Logger :: LOG_LEVEL_FATAL, __func__, __FILE__, __LINE__, __VA_ARGS__)
138#define OOFEM_LOG_ERROR(...) oofem_logger.writeELogMsg(Logger :: LOG_LEVEL_ERROR, __func__, __FILE__, __LINE__, __VA_ARGS__)
139#define OOFEM_LOG_WARNING(...) oofem_logger.writeELogMsg(Logger :: LOG_LEVEL_WARNING, __func__, __FILE__, __LINE__, __VA_ARGS__)
140
141#define OOFEM_LOG_FORCED(...) oofem_logger.writeLogMsg(Logger :: LOG_LEVEL_FORCED, __VA_ARGS__)
142#define OOFEM_LOG_RELEVANT(...) oofem_logger.writeLogMsg(Logger :: LOG_LEVEL_RELEVANT, __VA_ARGS__)
143#define OOFEM_LOG_INFO(...) oofem_logger.writeLogMsg(Logger :: LOG_LEVEL_INFO, __VA_ARGS__)
144#define OOFEM_LOG_DEBUG(...) oofem_logger.writeLogMsg(Logger :: LOG_LEVEL_DEBUG, __VA_ARGS__)
146} // end namespace oofem
147#endif // logger_h
void setComm(MPI_Comm comm)
Parallell comm.
Definition logger.C:248
void setLogLevel(logLevelType level)
Sets log level to given one. Only log messages with level less or equal given threshold will be print...
Definition logger.h:114
void flush()
Flushes the log stream.
Definition logger.h:111
bool closeFlag
flag indicating whether to close mylogStream.
Definition logger.h:73
void incrementErrorCounter()
Increment error count by one.
Definition logger.h:118
logLevelType
Type defining basic log levels.
Definition logger.h:61
@ LOG_LEVEL_ALL
Definition logger.h:67
@ LOG_LEVEL_INFO
Definition logger.h:66
@ LOG_LEVEL_FORCED
Definition logger.h:62
@ LOG_LEVEL_ERROR
Definition logger.h:63
@ LOG_LEVEL_FATAL
Definition logger.h:63
@ LOG_LEVEL_DEBUG
Definition logger.h:67
@ LOG_LEVEL_WARNING
Definition logger.h:64
@ LOG_LEVEL_RELEVANT
Definition logger.h:65
int numberOfWrn
Counter of all warning and error messages.
Definition logger.h:77
int numberOfErr
Definition logger.h:77
void appendLogTo(const std ::string &fname)
Redirects log output to given file name (with path).
Definition logger.C:76
MPI_Comm comm
Parallell comm.
Definition logger.h:80
void writeLogMsg(logLevelType level, const char *format,...)
Writes the normal log message.
Definition logger.C:148
bool errCloseFlag
Definition logger.h:73
void appendErrorTo(const std ::string &fname)
Redirects error output to given file name (with path).
Definition logger.C:95
void getNumberOfWarningsAndErrors(int &nwrns, int &nerrs)
Returns local (mpi-process) statistics.
Definition logger.h:122
FILE * errStream
Definition logger.h:71
logLevelType logLevel
Current log level, messages with higher level are not reported.
Definition logger.h:75
void writeELogMsg(logLevelType level, const char *_func, const char *_file, int _line, const char *format,...)
Writes extended log message with file and line info.
Definition logger.C:179
FILE * logStream
Stream used for logging.
Definition logger.h:71
Logger(logLevelType level)
Definition logger.C:52
Logger oofem_logger(Logger ::LOG_LEVEL_INFO)
Definition logger.h:131
#define OOFEM_EXPORT
Definition oofemcfg.h:7

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011