Peano 4
Loading...
Searching...
No Matches
Log.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#ifdef Parallel
6#include <mpi.h>
7#endif
8#include <iostream>
9#include <sstream>
10#include <functional>
11
12#ifdef __APPLE__
13#include <mach/mach_time.h>
14#include <mach/mach.h>
15#include <mach/clock.h>
16#endif
17
18#include <ctime>
19#include <chrono>
20
21#include "config.h"
22
23namespace tarch {
24 namespace logging {
25 class Log;
26 class CommandLineLogger;
27 class ChromeTraceFileLogger;
28 class NVTXLogger;
29 class ITACLogger;
30 class ITTLogger;
31 class ScorePLogger;
32 }
33}
34
35#if PeanoDebug>=4
39#define logDebug(methodName, logMacroMessageStream) \
40 { \
41 auto logMacroMessage = [&](void) -> std::string { \
42 std::ostringstream conv; \
43 conv << logMacroMessageStream; \
44 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
45 return conv.str(); \
46 }; \
47 _log.debug (methodName, logMacroMessage); \
48 }
49#else
50#define logDebug(methodName, logMacroMessageStream)
51#endif
52
53#if PeanoDebug>=1
54#define logTraceIn(methodName) \
55 { \
56 auto logMacroMessage = [&](void) -> std::string { \
57 std::ostringstream conv; \
58 conv << "in (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
59 return conv.str(); \
60 }; \
61 _log.traceIn(methodName, logMacroMessage); \
62 _log.indent(true,_log.getTraceInformation(methodName), logMacroMessage); \
63 }
64
65#define logTraceInWith1Argument(methodName,argument0) \
66 { \
67 auto logMacroMessage = [&](void) -> std::string { \
68 std::ostringstream conv; \
69 conv << "in:" << #argument0 << ":" << argument0; \
70 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
71 return conv.str(); \
72 }; \
73 _log.traceIn (methodName, logMacroMessage); \
74 _log.indent(true, _log.getTraceInformation(methodName), logMacroMessage); \
75 }
76
77#define logTraceInWith2Arguments(methodName,argument0,argument1) \
78 { \
79 auto logMacroMessage = [&](void) -> std::string { \
80 std::ostringstream conv; \
81 conv << "in:" << #argument0 << ":" << argument0; \
82 conv << "," << #argument1 << ":" << argument1; \
83 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
84 return conv.str(); \
85 }; \
86 _log.traceIn (methodName, logMacroMessage); \
87 _log.indent(true, _log.getTraceInformation(methodName), logMacroMessage); \
88 }
89
90#define logTraceInWith3Arguments(methodName,argument0,argument1,argument2) \
91 { \
92 auto logMacroMessage = [&](void) -> std::string { \
93 std::ostringstream conv; \
94 conv << "in:" << #argument0 << ":" << argument0; \
95 conv << "," << #argument1 << ":" << argument1; \
96 conv << "," << #argument2 << ":" << argument2; \
97 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
98 return conv.str(); \
99 }; \
100 _log.traceIn (methodName, logMacroMessage); \
101 _log.indent(true,_log.getTraceInformation(methodName), logMacroMessage); \
102 }
103
104#define logTraceInWith4Arguments(methodName,argument0,argument1,argument2,argument3) \
105 { \
106 auto logMacroMessage = [&](void) -> std::string { \
107 std::ostringstream conv; \
108 conv << "in:" << #argument0 << ":" << argument0; \
109 conv << "," << #argument1 << ":" << argument1; \
110 conv << "," << #argument2 << ":" << argument2; \
111 conv << "," << #argument3 << ":" << argument3; \
112 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
113 return conv.str(); \
114 }; \
115 _log.traceIn (methodName, logMacroMessage); \
116 _log.indent(true,_log.getTraceInformation(methodName), logMacroMessage); \
117 }
118
119#define logTraceInWith5Arguments(methodName,argument0,argument1,argument2,argument3,argument4) \
120 { \
121 auto logMacroMessage = [&](void) -> std::string { \
122 std::ostringstream conv; \
123 conv << "in:" << #argument0 << ":" << argument0; \
124 conv << "," << #argument1 << ":" << argument1; \
125 conv << "," << #argument2 << ":" << argument2; \
126 conv << "," << #argument3 << ":" << argument3; \
127 conv << "," << #argument4 << ":" << argument4; \
128 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
129 return conv.str(); \
130 }; \
131 _log.traceIn (methodName, logMacroMessage); \
132 _log.indent(true,_log.getTraceInformation(methodName), logMacroMessage); \
133 }
134
135#define logTraceInWith6Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5) \
136 { \
137 auto logMacroMessage = [&](void) -> std::string { \
138 std::ostringstream conv; \
139 conv << "in:" << #argument0 << ":" << argument0; \
140 conv << "," << #argument1 << ":" << argument1; \
141 conv << "," << #argument2 << ":" << argument2; \
142 conv << "," << #argument3 << ":" << argument3; \
143 conv << "," << #argument4 << ":" << argument4; \
144 conv << "," << #argument5 << ":" << argument5; \
145 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
146 return conv.str(); \
147 }; \
148 _log.traceIn (methodName, logMacroMessage); \
149 _log.indent(true,_log.getTraceInformation(methodName), logMacroMessage); \
150 }
151
152#define logTraceInWith7Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6) \
153 { \
154 auto logMacroMessage = [&](void) -> std::string { \
155 std::ostringstream conv; \
156 conv << "in:" << #argument0 << ":" << argument0; \
157 conv << "," << #argument1 << ":" << argument1; \
158 conv << "," << #argument2 << ":" << argument2; \
159 conv << "," << #argument3 << ":" << argument3; \
160 conv << "," << #argument4 << ":" << argument4; \
161 conv << "," << #argument5 << ":" << argument5; \
162 conv << "," << #argument6 << ":" << argument6; \
163 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
164 return conv.str(); \
165 }; \
166 _log.traceIn (methodName, logMacroMessage); \
167 _log.indent(true,_log.getTraceInformation(methodName), logMacroMessage); \
168 }
169
170#define logTraceInWith8Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6,argument7) \
171 { \
172 auto logMacroMessage = [&](void) -> std::string { \
173 std::ostringstream conv; \
174 conv << "in:" << #argument0 << ":" << argument0; \
175 conv << "," << #argument1 << ":" << argument1; \
176 conv << "," << #argument2 << ":" << argument2; \
177 conv << "," << #argument3 << ":" << argument3; \
178 conv << "," << #argument4 << ":" << argument4; \
179 conv << "," << #argument5 << ":" << argument5; \
180 conv << "," << #argument6 << ":" << argument6; \
181 conv << "," << #argument7 << ":" << argument7; \
182 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
183 return conv.str(); \
184 }; \
185 _log.traceIn (methodName, logMacroMessage); \
186 _log.indent(true,_log.getTraceInformation(methodName), logMacroMessage); \
187 }
188
189#define logTraceInWith9Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6,argument7,argument8) \
190 { \
191 auto logMacroMessage = [&](void) -> std::string { \
192 std::ostringstream conv; \
193 conv << "in:" << #argument0 << ":" << argument0; \
194 conv << "," << #argument1 << ":" << argument1; \
195 conv << "," << #argument2 << ":" << argument2; \
196 conv << "," << #argument3 << ":" << argument3; \
197 conv << "," << #argument4 << ":" << argument4; \
198 conv << "," << #argument5 << ":" << argument5; \
199 conv << "," << #argument6 << ":" << argument6; \
200 conv << "," << #argument7 << ":" << argument7; \
201 conv << "," << #argument8 << ":" << argument8; \
202 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
203 return conv.str(); \
204 }; \
205 _log.traceIn (methodName, logMacroMessage); \
206 _log.indent(true,_log.getTraceInformation(methodName), logMacroMessage); \
207 }
208
209#define logTraceOut(methodName) \
210 { \
211 auto logMacroMessage = [&](void) -> std::string { \
212 std::ostringstream conv; \
213 conv << "out (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
214 return conv.str(); \
215 }; \
216 _log.indent(false,_log.getTraceInformation(methodName),logMacroMessage); \
217 _log.traceOut (methodName, logMacroMessage); \
218 }
219
220#define logTraceOutWith1Argument(methodName,argument0) \
221 { \
222 auto logMacroMessage = [&](void) -> std::string { \
223 std::ostringstream conv; \
224 conv << "out:" << #argument0 << ":" << argument0; \
225 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
226 return conv.str(); \
227 }; \
228 _log.indent(false,_log.getTraceInformation(methodName), logMacroMessage); \
229 _log.traceOut (methodName, logMacroMessage); \
230 }
231
232#define logTraceOutWith2Arguments(methodName,argument0,argument1) \
233 { \
234 auto logMacroMessage = [&](void) -> std::string { \
235 std::ostringstream conv; \
236 conv << "out:" << #argument0 << ":" << argument0; \
237 conv << "," << #argument1 << ":" << argument1; \
238 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
239 return conv.str(); \
240 }; \
241 _log.indent(false,_log.getTraceInformation(methodName), logMacroMessage); \
242 _log.traceOut (methodName, logMacroMessage); \
243 }
244
245#define logTraceOutWith3Arguments(methodName,argument0,argument1,argument2) \
246 { \
247 auto logMacroMessage = [&](void) -> std::string { \
248 std::ostringstream conv; \
249 conv << "out:" << #argument0 << ":" << argument0; \
250 conv << "," << #argument1 << ":" << argument1; \
251 conv << "," << #argument2 << ":" << argument2; \
252 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
253 return conv.str(); \
254 }; \
255 _log.indent(false,_log.getTraceInformation(methodName), logMacroMessage); \
256 _log.traceOut (methodName, logMacroMessage); \
257 }
258
259#define logTraceOutWith4Arguments(methodName,argument0,argument1,argument2,argument3) \
260 { \
261 auto logMacroMessage = [&](void) -> std::string { \
262 std::ostringstream conv; \
263 conv << "out:" << #argument0 << ":" << argument0; \
264 conv << "," << #argument1 << ":" << argument1; \
265 conv << "," << #argument2 << ":" << argument2; \
266 conv << "," << #argument3 << ":" << argument3; \
267 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
268 return conv.str(); \
269 }; \
270 _log.indent(false,_log.getTraceInformation(methodName), logMacroMessage); \
271 _log.traceOut (methodName, logMacroMessage); \
272 }
273
274#define logTraceOutWith5Arguments(methodName,argument0,argument1,argument2,argument3,argument4) \
275 { \
276 auto logMacroMessage = [&](void) -> std::string { \
277 std::ostringstream conv; \
278 conv << "out:" << #argument0 << ":" << argument0; \
279 conv << "," << #argument1 << ":" << argument1; \
280 conv << "," << #argument2 << ":" << argument2; \
281 conv << "," << #argument3 << ":" << argument3; \
282 conv << "," << #argument4 << ":" << argument4; \
283 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
284 return conv.str(); \
285 }; \
286 _log.indent(false,_log.getTraceInformation(methodName), logMacroMessage); \
287 _log.traceOut (methodName, logMacroMessage); \
288 }
289
290#define logTraceOutWith6Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5) \
291 { \
292 auto logMacroMessage = [&](void) -> std::string { \
293 std::ostringstream conv; \
294 conv << "out:" << #argument0 << ":" << argument0; \
295 conv << "," << #argument1 << ":" << argument1; \
296 conv << "," << #argument2 << ":" << argument2; \
297 conv << "," << #argument3 << ":" << argument3; \
298 conv << "," << #argument4 << ":" << argument4; \
299 conv << "," << #argument5 << ":" << argument5; \
300 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
301 return conv.str(); \
302 }; \
303 _log.indent(false,_log.getTraceInformation(methodName), logMacroMessage); \
304 _log.traceOut (methodName, logMacroMessage); \
305 }
306
307#define logTraceOutWith7Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6) \
308 { \
309 auto logMacroMessage = [&](void) -> std::string { \
310 std::ostringstream conv; \
311 conv << "out:" << #argument0 << ":" << argument0; \
312 conv << "," << #argument1 << ":" << argument1; \
313 conv << "," << #argument2 << ":" << argument2; \
314 conv << "," << #argument3 << ":" << argument3; \
315 conv << "," << #argument4 << ":" << argument4; \
316 conv << "," << #argument5 << ":" << argument5; \
317 conv << "," << #argument6 << ":" << argument6; \
318 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
319 return conv.str(); \
320 }; \
321 _log.indent(false,_log.getTraceInformation(methodName), logMacroMessage); \
322 _log.traceOut (methodName, logMacroMessage); \
323 }
324
325
326#define logTraceOutWith8Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6,argument7) \
327 { \
328 auto logMacroMessage = [&](void) -> std::string { \
329 std::ostringstream conv; \
330 conv << "out:" << #argument0 << ":" << argument0; \
331 conv << "," << #argument1 << ":" << argument1; \
332 conv << "," << #argument2 << ":" << argument2; \
333 conv << "," << #argument3 << ":" << argument3; \
334 conv << "," << #argument4 << ":" << argument4; \
335 conv << "," << #argument5 << ":" << argument5; \
336 conv << "," << #argument6 << ":" << argument6; \
337 conv << "," << #argument7 << ":" << argument7; \
338 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
339 return conv.str(); \
340 }; \
341 _log.indent(false,_log.getTraceInformation(methodName),logMacroMessage); \
342 _log.traceOut (methodName, logMacroMessage); \
343 }
344
345#define logTraceOutWith12Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6,argument7,argument8,argument9,argument10,argument11) \
346 { \
347 auto logMacroMessage = [&](void) -> std::string { \
348 std::ostringstream conv; \
349 conv << "out:" << #argument0 << ":" << argument0; \
350 conv << "," << #argument1 << ":" << argument1; \
351 conv << "," << #argument2 << ":" << argument2; \
352 conv << "," << #argument3 << ":" << argument3; \
353 conv << "," << #argument4 << ":" << argument4; \
354 conv << "," << #argument5 << ":" << argument5; \
355 conv << "," << #argument6 << ":" << argument6; \
356 conv << "," << #argument7 << ":" << argument7; \
357 conv << "," << #argument8 << ":" << argument8; \
358 conv << "," << #argument9 << ":" << argument9; \
359 conv << "," << #argument10 << ":" << argument10; \
360 conv << "," << #argument11 << ":" << argument11; \
361 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
362 return conv.str(); \
363 }; \
364 _log.indent(false,_log.getTraceInformation(methodName),logMacroMessage); \
365 _log.traceOut (methodName, logMacroMessage); \
366 }
367
368#else
369#define logTraceIn(methodName)
370#define logTraceInWith1Argument(methodName,argument0)
371#define logTraceInWith2Arguments(methodName,argument0,argument1)
372#define logTraceInWith3Arguments(methodName,argument0,argument1,argument2)
373#define logTraceInWith4Arguments(methodName,argument0,argument1,argument2,argument3)
374#define logTraceInWith5Arguments(methodName,argument0,argument1,argument2,argument3,argument4)
375#define logTraceInWith6Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5)
376#define logTraceInWith7Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6)
377#define logTraceInWith8Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6,argument7)
378#define logTraceInWith9Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6,argument7,argument8)
379#define logTraceOut(methodName)
380#define logTraceOutWith1Argument(methodName,argument0)
381#define logTraceOutWith2Arguments(methodName,argument0,argument1)
382#define logTraceOutWith3Arguments(methodName,argument0,argument1,argument2)
383#define logTraceOutWith4Arguments(methodName,argument0,argument1,argument2,argument3)
384#define logTraceOutWith5Arguments(methodName,argument0,argument1,argument2,argument3,argument4)
385#define logTraceOutWith6Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5)
386#define logTraceOutWith7Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6)
387#define logTraceOutWith8Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6,argument7)
388#define logTraceOutWith12Arguments(methodName,argument0,argument1,argument2,argument3,argument4,argument5,argument6,argument7,argument8,argument9,argument10,argument11)
389#endif
390
411#define logInfo(methodName, logMacroMessageStream) \
412 { \
413 auto logMacroMessage = [&](void) -> std::string { \
414 std::ostringstream conv; \
415 conv << logMacroMessageStream; \
416 return conv.str(); \
417 }; \
418 _log.info (methodName, logMacroMessage); \
419 }
420
421#define logExceptionAndQuit(exception) \
422 { \
423 std::cerr << std::string("caught exception (file:)") << __FILE__ << std::string(", line:") << __LINE__ << std::string("): ") << std::string(exception.what()); \
424 exit(-1); \
425 }
426
440#define logWarning(methodName, logMacroMessageStream) \
441 { \
442 auto logMacroMessage = [&](void) -> std::string { \
443 std::ostringstream conv; \
444 conv << logMacroMessageStream; \
445 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
446 return conv.str(); \
447 }; \
448 _log.warning(methodName, logMacroMessage); \
449 }
450
464#define logError(methodName, logMacroMessageStream) \
465 { \
466 auto logMacroMessage = [&](void) -> std::string { \
467 std::ostringstream conv; \
468 conv << logMacroMessageStream; \
469 conv << " (file:" << __FILE__ << ",line:" << __LINE__ << ")"; \
470 return conv.str(); \
471 }; \
472 _log.error (methodName, logMacroMessage); \
473 }
474
517 private:
518 #if !defined(UseLogService)
520 #endif
521
525 long int getTimeStamp() const;
526
530 std::string _className;
531
532 std::chrono::system_clock::time_point _startupTime;
533
534 #ifdef __APPLE__
535 clock_serv_t cclock;
536 #endif
537 public:
543 static std::string getMachineInformation();
544
552 Log(const std::string& className);
553
557 virtual ~Log();
558
563 static void exception( const std::bad_alloc& exception, const std::string& file, const int lineNumber );
564
577 typedef std::function< std::string(void) > Message;
578
597 #if PeanoDebug>=4
598 void debug(const std::string& methodName, Message logMacroMessage);
599 #else
600 inline void debug([[maybe_unused]] const std::string& methodName, [[maybe_unused]] Message logMacroMessage) const {}
601 #endif
602
618 void info(const std::string& methodName, Message logMacroMessage);
619
635 void warning(const std::string& methodName, Message logMacroMessage);
636
652 void error(const std::string& methodName, Message logMacroMessage);
653
654 #if PeanoDebug>=1
655 void traceIn(const std::string& methodName, Message logMacroMessage);
656 void traceOut(const std::string& methodName, Message logMacroMessage);
657 #else
658 void traceIn(const std::string& methodName, Message logMacroMessage);
659 void traceOut(const std::string& methodName, Message logMacroMessage);
660 #endif
661
668 void indent( bool indent, const std::string& trace, Message logMacroMessage ) const;
669
670 std::string getTraceInformation( const std::string& methodName ) const;
671
672 static void flushBeforeAssertion();
673};
Log Device.
Definition Log.h:516
virtual ~Log()
Destructor.
Definition Log.cpp:51
std::chrono::system_clock::time_point _startupTime
Definition Log.h:532
void traceIn(const std::string &methodName, Message logMacroMessage)
Definition Log.cpp:90
CommandLineLogger UseLogService
Definition Log.h:519
static std::string getMachineInformation()
Writes information about the computer the output is written from.
Definition Log.cpp:99
std::string getTraceInformation(const std::string &methodName) const
Definition Log.cpp:140
long int getTimeStamp() const
Returns the time stamp in nanoseconds.
Definition Log.cpp:133
void error(const std::string &methodName, Message logMacroMessage)
Log an Error.
Definition Log.cpp:73
void debug(const std::string &methodName, Message logMacroMessage) const
Log Debug Information.
Definition Log.h:600
Log(const std::string &className)
Constructor.
Definition Log.cpp:45
std::function< std::string(void) > Message
We could make the logMacroMessage passed into a log statement a string.
Definition Log.h:577
void info(const std::string &methodName, Message logMacroMessage)
Log Information.
Definition Log.cpp:61
static void flushBeforeAssertion()
Definition Log.cpp:129
void warning(const std::string &methodName, Message logMacroMessage)
Log a Warning.
Definition Log.cpp:67
std::string _className
Name of the class that is using the interface.
Definition Log.h:530
void traceOut(const std::string &methodName, Message logMacroMessage)
Definition Log.cpp:92
static void exception(const std::bad_alloc &exception, const std::string &file, const int lineNumber)
Logs and exception and stops the application.
void indent(bool indent, const std::string &trace, Message logMacroMessage) const
Indent the Subsequent Messages.
Definition Log.cpp:95
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:17