OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
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 - 2013 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 "oofemcfg.h"
39 
40 #include <cstdio>
41 #include <string>
42 #ifdef __PARALLEL_MODE
43 #include <mpi.h>
44 #endif
45 
46 // MSVC doesn't properly implement C99. (might need to wrap __func__ behind a macro to support all platforms correctly(?))
47 #ifdef _MSC_VER
48 # define __func__ __FUNCTION__
49 #endif
50 
51 namespace oofem {
56 class OOFEM_EXPORT Logger
57 {
58 public:
60  enum logLevelType {
61  LOG_LEVEL_FORCED=-1,
62  LOG_LEVEL_FATAL=0, LOG_LEVEL_ERROR=0,
63  LOG_LEVEL_WARNING = 1,
64  LOG_LEVEL_RELEVANT = 2,
65  LOG_LEVEL_INFO = 3,
66  LOG_LEVEL_ALL = 4, LOG_LEVEL_DEBUG = 4
67  };
68 protected:
70  FILE *logStream, *errStream;
72  bool closeFlag, errCloseFlag;
76  int numberOfWrn, numberOfErr;
77 #ifdef __PARALLEL_MODE
78  MPI_Comm comm;
80 #endif
81 public:
82  Logger(logLevelType level);
83  ~Logger();
85  void appendLogTo(const std :: string &fname);
87  void appendErrorTo(const std :: string &fname);
89  void appendLogTo(FILE* stream);
91  void appendErrorTo(FILE* stream);
92 #ifdef __PARALLEL_MODE
93  void setComm(MPI_Comm comm);
95 #endif
96 
98  void writeLogMsg(logLevelType level, const char *format, ...);
100  void writeELogMsg(logLevelType level, const char *_func, const char *_file, int _line, const char *format, ...);
102  void flush() { fflush(logStream); fflush(errStream); }
103 
105  void setLogLevel(logLevelType level) { logLevel = level; }
107  void setLogLevel(int level);
109  void printStatistics();
110 
111 protected:
112  const char *giveLevelName(logLevelType l) const;
113 };
114 
115 extern OOFEM_EXPORT Logger oofem_logger;
116 
121 #define OOFEM_LOG_FATAL(...) oofem_logger.writeELogMsg(Logger :: LOG_LEVEL_FATAL, __func__, __FILE__, __LINE__, __VA_ARGS__)
122 #define OOFEM_LOG_ERROR(...) oofem_logger.writeELogMsg(Logger :: LOG_LEVEL_ERROR, __func__, __FILE__, __LINE__, __VA_ARGS__)
123 #define OOFEM_LOG_WARNING(...) oofem_logger.writeELogMsg(Logger :: LOG_LEVEL_WARNING, __func__, __FILE__, __LINE__, __VA_ARGS__)
124 
125 #define OOFEM_LOG_FORCED(...) oofem_logger.writeLogMsg(Logger :: LOG_LEVEL_FORCED, __VA_ARGS__)
126 #define OOFEM_LOG_RELEVANT(...) oofem_logger.writeLogMsg(Logger :: LOG_LEVEL_RELEVANT, __VA_ARGS__)
127 #define OOFEM_LOG_INFO(...) oofem_logger.writeLogMsg(Logger :: LOG_LEVEL_INFO, __VA_ARGS__)
128 #define OOFEM_LOG_DEBUG(...) oofem_logger.writeLogMsg(Logger :: LOG_LEVEL_DEBUG, __VA_ARGS__)
129 
130 } // end namespace oofem
131 #endif // logger_h
bool errCloseFlag
Definition: logger.h:72
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:105
FILE * logStream
Stream used for logging.
Definition: logger.h:70
void flush()
Flushes the log stream.
Definition: logger.h:102
Logger oofem_logger(Logger::LOG_LEVEL_INFO)
Definition: logger.h:115
Logger class used by OOFEM to print information during analysis.
Definition: logger.h:56
logLevelType logLevel
Current log level, messages with higher level are not reported.
Definition: logger.h:74
logLevelType
Type defining basic log levels.
Definition: logger.h:60
int numberOfWrn
Counter of all warning and error messages.
Definition: logger.h:76
the oofem namespace is to define a context or scope in which all oofem names are defined.

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:29 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011