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