DOLFIN
DOLFIN C++ interface
log.h
1 // Copyright (C) 2003-2016 Anders Logg and Jim Tilander
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Modified by Ola Skavhaug 2007, 2009
19 //
20 // First added: 2003-03-13
21 // Last changed: 2016-06-10
22 
23 #ifndef __LOG_H
24 #define __LOG_H
25 
26 #include <string>
27 #include "LogLevel.h"
28 
29 namespace dolfin
30 {
31 
32  class Variable;
33  class Parameters;
34 
42 
44  void info(std::string msg, ...);
45 
47  void info(const Parameters& parameters, bool verbose=false);
48 
50  void info(const Variable& variable, bool verbose=false);
51 
53  void info_stream(std::ostream& out, std::string msg);
54 
56  void info_underline(std::string msg, ...);
57 
59  void warning(std::string msg, ...);
60 
64  void error(std::string msg, ...);
65 
85  void dolfin_error(std::string location,
86  std::string task,
87  std::string reason, ...);
88 
98  void deprecation(std::string feature,
99  std::string version_deprecated,
100  std::string message, ...);
101 
103  void log(int debug_level, std::string msg, ...);
104 
106  void begin(std::string msg, ...);
107 
109  void begin(int debug_level, std::string msg, ...);
110 
112  void end();
113 
115  void set_log_active(bool active=true);
116 
118  void set_log_level(int level);
119 
121  void set_indentation_level(std::size_t indentation_level);
122 
124  void set_output_stream(std::ostream& out);
125 
127  int get_log_level();
128 
131  void monitor_memory_usage();
132 
135  void not_working_in_parallel(std::string what);
136 
137  // Helper function for dolfin_debug macro
138  void __debug(std::string file,
139  unsigned long line,
140  std::string function,
141  std::string format, ...);
142 
143  // Helper function for dolfin_dolfin_assert macro
144  void __dolfin_assert(std::string file,
145  unsigned long line,
146  std::string function,
147  std::string check);
148 
149 }
150 
151 // The following three macros are the only "functions" in DOLFIN
152 // named dolfin_foo. Other functions can be placed inside the
153 // DOLFIN namespace and therefore don't require a prefix.
154 
155 // Debug macros (with varying number of arguments)
156 #define dolfin_debug(msg) do { dolfin::__debug(__FILE__, __LINE__, __FUNCTION__, msg); } while (false)
157 #define dolfin_debug1(msg, a0) do { dolfin::__debug(__FILE__, __LINE__, __FUNCTION__, msg, a0); } while (false)
158 #define dolfin_debug2(msg, a0, a1) do { dolfin::__debug(__FILE__, __LINE__, __FUNCTION__, msg, a0, a1); } while (false)
159 #define dolfin_debug3(msg, a0, a1, a2) do { dolfin::__debug(__FILE__, __LINE__, __FUNCTION__, msg, a0, a1, a2); } while (false)
160 #define dolfin_debug4(msg, a0, a1, a2, a3) do { dolfin::__debug(__FILE__, __LINE__, __FUNCTION__, msg, a0, a1, a2, a3); } while (false)
161 
162 // Not implemented error, reporting function name and line number
163 #define dolfin_not_implemented() \
164  do { \
165  dolfin::dolfin_error("log.h", \
166  "perform call to DOLFIN function", \
167  "The function %s has not been implemented (in %s line %d)", \
168  __FUNCTION__, __FILE__, __LINE__); \
169  } while (false)
170 
171 // Assertion, only active if DEBUG is defined
172 #ifdef DEBUG
173 #define dolfin_assert(check) \
174  do { \
175  if (!(check)) \
176  { \
177  dolfin::__dolfin_assert(__FILE__, __LINE__, __FUNCTION__, #check); \
178  } \
179  } while (false)
180 #else
181 #define dolfin_assert(check)
182 #endif
183 
184 #endif
void set_log_level(int level)
Set log level.
Definition: log.cpp:180
void warning(std::string msg,...)
Print warning.
Definition: log.cpp:115
Definition: adapt.h:29
void begin(std::string msg,...)
Begin task (increase indentation level)
Definition: log.cpp:153
void deprecation(std::string feature, std::string version_deprecated, std::string message,...)
Definition: log.cpp:137
void info_underline(std::string msg,...)
Print underlined message.
Definition: log.cpp:107
void end()
End task (decrease indentation level)
Definition: log.cpp:168
void set_log_active(bool active=true)
Turn logging on or off.
Definition: log.cpp:175
void error(std::string msg,...)
Definition: log.cpp:123
void set_indentation_level(std::size_t indentation_level)
Set indentation level.
Definition: log.cpp:185
void log(int debug_level, std::string msg,...)
Print message at given debug level.
Definition: log.cpp:145
int get_log_level()
Get log level.
Definition: log.cpp:195
void info(std::string msg,...)
Print message.
Definition: log.cpp:72
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129
void monitor_memory_usage()
Definition: log.cpp:200
void not_working_in_parallel(std::string what)
Definition: log.cpp:205
GlobalParameters parameters
The global parameter database.
Definition: GlobalParameters.cpp:32
void info_stream(std::ostream &out, std::string msg)
Print message to stream.
Definition: log.cpp:97
void set_output_stream(std::ostream &out)
Set output stream.
Definition: log.cpp:190