Peano 4
Loading...
Searching...
No Matches
Log.cpp
Go to the documentation of this file.
1#include "tarch/logging/Log.h"
3#include "tarch/Assertions.h"
5
6#include "config.h"
7
10
11#if UseLogService==ChromeTraceFileLogger
13#endif
14
15#if UseLogService==NVTXLogger
16#include "NVTXLogger.h"
17#endif
18
19#if UseLogService==ITACLogger
20#include "ITACLogger.h"
21#endif
22
23#if UseLogService==ITTLogger
24#include "ITTLogger.h"
25#endif
26
27#if UseLogService==ScorePLogger
28#include "ScorePLogger.h"
29#endif
30
35#ifdef CompilerHasUTSName
36#include <sys/utsname.h>
37#endif
38
39#include "tarch/mpi/Rank.h"
40
41#include <time.h>
42
44
45tarch::logging::Log::Log(const std::string& className):
46 _className( className ) {
47
48 _startupTime = std::chrono::system_clock::now();
49}
50
52
53#if PeanoDebug>=4
54void tarch::logging::Log::debug(const std::string& methodName, Message message) {
55 if (LogFilter::getInstance().writeDebug( _className )) {
56 UseLogService::getInstance().debug(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
57 }
58}
59#endif
60
61void tarch::logging::Log::info(const std::string& methodName, Message message) {
62 if (LogFilter::getInstance().writeInfo( _className )) {
63 UseLogService::getInstance().info(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
64 }
65}
66
67void tarch::logging::Log::warning(const std::string& methodName, Message message) {
68 if (LogFilter::getInstance().writeWarning( _className )) {
69 UseLogService::getInstance().warning(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
70 }
71}
72
73void tarch::logging::Log::error(const std::string& methodName, Message message) {
74 UseLogService::getInstance().error(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
75}
76
77#if PeanoDebug>=1
78void tarch::logging::Log::traceIn(const std::string& methodName, Message message) {
79 if (LogFilter::getInstance().writeTrace( _className )) {
80 UseLogService::getInstance().traceIn(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
81 }
82}
83
84void tarch::logging::Log::traceOut(const std::string& methodName, Message message) {
85 if (LogFilter::getInstance().writeTrace( _className )) {
86 UseLogService::getInstance().traceOut(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
87 }
88}
89#else
90void tarch::logging::Log::traceIn(const std::string&, Message) {}
91
92void tarch::logging::Log::traceOut(const std::string&, Message) {}
93#endif
94
95void tarch::logging::Log::indent( bool indent, const std::string& trace, Message message ) const {
96 UseLogService::getInstance().indent( indent, trace, message() );
97}
98
100 std::ostringstream message;
101
102 #ifdef CompilerHasUTSName
103 utsname* utsdata = new utsname();
104 assertion( utsdata!=NULL );
105 uname(utsdata);
106
107 message << "[" << utsdata->nodename << "]";
108
109 #ifdef Parallel
110 message << ",";
111 #endif
112
113 delete utsdata;
114 #endif
115
116 #ifdef Parallel
117 if (tarch::mpi::Rank::getInstance().isInitialised()) {
118 message << "rank:" << tarch::mpi::Rank::getInstance().getRank();
119 } else {
120 message << "rank:not-initialised-yet";
121 }
122 #else
123 message << "rank:0";
124 #endif
125
126 return message.str();
127}
128
130 UseLogService::getInstance().close();
131}
132
134 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
135 long int result = std::chrono::duration_cast<std::chrono::nanoseconds>(now - _startupTime).count();
136 assertion1(result>=0,result);
137 return result;
138}
139
140std::string tarch::logging::Log::getTraceInformation( const std::string& methodName ) const {
141 return _className + "::" + methodName;
142}
#define assertion1(expr, param)
#define assertion(expr)
static LogFilter & getInstance()
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
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
void traceOut(const std::string &methodName, Message logMacroMessage)
Definition Log.cpp:92
void indent(bool indent, const std::string &trace, Message logMacroMessage) const
Indent the Subsequent Messages.
Definition Log.cpp:95
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:538
int getRank() const
Return rank of this node.
Definition Rank.cpp:528
static Core & getInstance()
Definition Core.cpp:55