Peano
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
45std::chrono::system_clock::time_point tarch::logging::Log::_startupTime{ std::chrono::system_clock::now() };
46
47
48tarch::logging::Log::Log(const std::string& className):
49 _className( className ) {
50}
51
53
54#if PeanoDebug>=4
55void tarch::logging::Log::debug(const std::string& methodName, Message message) {
56 if (LogFilter::getInstance().writeDebug( _className )) {
57 UseLogService::getInstance().debug(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
58 }
59}
60#endif
61
62void tarch::logging::Log::info(const std::string& methodName, Message message) {
63 if (LogFilter::getInstance().writeInfo( _className )) {
64 UseLogService::getInstance().info(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
65 }
66}
67
68void tarch::logging::Log::warning(const std::string& methodName, Message message) {
69 if (LogFilter::getInstance().writeWarning( _className )) {
70 UseLogService::getInstance().warning(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
71 }
72}
73
74void tarch::logging::Log::error(const std::string& methodName, Message message) {
75 UseLogService::getInstance().error(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
76}
77
78#if PeanoDebug>=1
79void tarch::logging::Log::traceIn(const std::string& methodName, Message message) {
80 if (LogFilter::getInstance().writeTrace( _className )) {
81 UseLogService::getInstance().traceIn(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
82 }
83}
84
85void tarch::logging::Log::traceOut(const std::string& methodName, Message message) {
86 if (LogFilter::getInstance().writeTrace( _className )) {
87 UseLogService::getInstance().traceOut(getTimeStamp(),tarch::mpi::Rank::getInstance().getRank(),tarch::multicore::Core::getInstance().getCoreNumber(),getTraceInformation(methodName),message());
88 }
89}
90#else
91void tarch::logging::Log::traceIn(const std::string&, Message) {}
92
93void tarch::logging::Log::traceOut(const std::string&, Message) {}
94#endif
95
96void tarch::logging::Log::indent( bool indent, const std::string& trace, Message message ) const {
97 UseLogService::getInstance().indent( indent, trace, message() );
98}
99
101 std::ostringstream message;
102
103 #ifdef CompilerHasUTSName
104 utsname* utsdata = new utsname();
105 assertion( utsdata!=NULL );
106 uname(utsdata);
107
108 message << "[" << utsdata->nodename << "]";
109
110 #ifdef Parallel
111 message << ",";
112 #endif
113
114 delete utsdata;
115 #endif
116
117 #ifdef Parallel
118 if (tarch::mpi::Rank::getInstance().isInitialised()) {
119 message << "rank:" << tarch::mpi::Rank::getInstance().getRank();
120 } else {
121 message << "rank:not-initialised-yet";
122 }
123 #else
124 message << "rank:0";
125 #endif
126
127 return message.str();
128}
129
131 UseLogService::getInstance().close();
132}
133
135 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
136 long int result = std::chrono::duration_cast<std::chrono::nanoseconds>(now - _startupTime).count();
137 assertion1(result>=0,result);
138 return result;
139}
140
141std::string tarch::logging::Log::getTraceInformation( const std::string& methodName ) const {
142 return _className + "::" + methodName;
143}
#define assertion1(expr, param)
#define assertion(expr)
static LogFilter & getInstance()
virtual ~Log()
Destructor.
Definition Log.cpp:52
static std::chrono::system_clock::time_point _startupTime
For the machine name.
Definition Log.h:45
void traceIn(const std::string &methodName, Message logMacroMessage)
Definition Log.cpp:91
static std::string getMachineInformation()
Writes information about the computer the output is written from.
Definition Log.cpp:100
std::string getTraceInformation(const std::string &methodName) const
Definition Log.cpp:141
long int getTimeStamp() const
Returns the time stamp in nanoseconds.
Definition Log.cpp:134
void error(const std::string &methodName, Message logMacroMessage)
Log an Error.
Definition Log.cpp:74
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:48
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:62
static void flushBeforeAssertion()
Definition Log.cpp:130
void warning(const std::string &methodName, Message logMacroMessage)
Log a Warning.
Definition Log.cpp:68
void traceOut(const std::string &methodName, Message logMacroMessage)
Definition Log.cpp:93
void indent(bool indent, const std::string &trace, Message logMacroMessage) const
Indent the Subsequent Messages.
Definition Log.cpp:96
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:539
int getRank() const
Return rank of this node.
Definition Rank.cpp:529
static Core & getInstance()
Definition Core.cpp:57