36 _outputStream(nullptr),
37 _hasWrittenToOuputStream(false),
57 if (_outputStream==
nullptr) {
60 _hasWrittenToOuputStream =
true;
61 return *_outputStream;
67 out().setf( std::ios_base::scientific, std::ios_base::floatfield );
69 std::cerr.setf( std::ios_base::scientific, std::ios_base::floatfield );
70 std::cerr.precision(20);
88 if ( message.size() > 0 ) {
89 while (message.size() < spaces) {
92 message = getLogColumnSeparator() + message;
100 _iterationCounter ++;
103 if ( _indentTraces.size()>0 ) {
104 while (not _indentTraces.empty()) {
105 logWarning(
"closeOutputStreamAndReopenNewOne()",
"tag still open: " << _indentTraces.top() );
109 else if (_indent!=0) {
110 logWarning(
"closeOutputStreamAndReopenNewOne()",
"indent is " << _indent <<
". Indentation messed up - likely due to missing logTraceOut. Re-translate without shared memory parallelisation and rerun" );
116 reopenOutputStream();
121 long int timestampSeconds = timestampNanoseconds / 1000 / 1000 / 1000;
122 const int HourScaling = 60 * 60;
123 long int hours = timestampSeconds / HourScaling;
124 timestampSeconds = timestampSeconds - HourScaling * hours;
126 const int MinutesScaling = 60;
127 long int minutes = timestampSeconds / MinutesScaling;
128 timestampSeconds = timestampSeconds - MinutesScaling * minutes;
130 const int SecondsScaling = 1;
131 long int seconds = timestampSeconds / SecondsScaling;
133 std::stringstream result;
137 result << hours <<
":";
141 result << minutes <<
":";
151 std::string messageType,
152 long int timestampNanoseconds,
int rank,
int threadId,
const std::string& trace,
const std::string& message
154 assertion( _indent!=0 or _indentTraces.empty() );
156 std::string prefix =
"";
157 const unsigned int indent = _indent;
158 for (
unsigned int i=0; i<indent; i++ ) prefix +=
" ";
162 if ( getLogTimeStamp() ) {
163 std::ostringstream timeStampString;
164 timeStampString << timestampNanoseconds;
165 result += addSeparators(NumberOfStandardColumnSpaces,timeStampString.str() );
168 if ( getLogTimeStampHumanReadable() ) {
169 result += addSeparators(NumberOfStandardColumnSpaces,getTimeStampHumanReadable(timestampNanoseconds));
172 if ( getLogMachineName() ) {
173 result += addSeparators(NumberOfStandardColumnSpaces,
"rank:" + std::to_string(rank));
176 if ( getLogThreadName() ) {
177 result += addSeparators(NumberOfStandardColumnSpaces,
"core:" + std::to_string(threadId));
180 if ( getLogMessageType() ) {
181 result += addSeparators(NumberOfStandardColumnSpaces,messageType);
184 if ( getLogTrace() ) {
185 result += addSeparators(NumberOfTraceColumnSpaces,trace);
188 result += addSeparators(NumberOfStandardColumnSpaces,prefix + message);
197 #if !defined(PeanoDebug) || PeanoDebug<1
201 std::string outputMessage = constructMessageString(
203 timestampNanoseconds, rank, threadId, trace, message
207 out() << outputMessage;
213 std::string outputMessage = constructMessageString(
215 timestampNanoseconds, rank, threadId, trace, message
219 out() << outputMessage;
220 if (_outputStream!=
nullptr) {
221 std::cout << outputMessage;
227 std::string outputMessage = constructMessageString(
229 timestampNanoseconds, rank, threadId, trace, message
233 if (_outputStream!=
nullptr) {
234 out() << outputMessage;
237 std::cerr << outputMessage;
243 std::string outputMessage = constructMessageString(
245 timestampNanoseconds, rank, threadId, trace, message
249 if (_outputStream!=
nullptr) {
250 out() << outputMessage;
253 std::cerr << outputMessage;
263 std::string outputMessage = constructMessageString(
265 timestampNanoseconds, rank, threadId, trace, message
269 out() << outputMessage;
275 std::string outputMessage = constructMessageString(
277 timestampNanoseconds, rank, threadId, trace, message
281 out() << outputMessage;
290 _indent+=NumberOfIndentSpaces;
292 _indentTraces.push(trace);
297 not _indentTraces.empty(),
310 _indent >= NumberOfIndentSpaces,
311 _indent, NumberOfIndentSpaces,
312 "more logTraceOut calls than logTraceIn calls invoked before",
316 _indent-=NumberOfIndentSpaces;
325 if (_outputStream!=
nullptr && _hasWrittenToOuputStream) {
326 _outputStream->flush();
327 delete _outputStream;
328 _outputStream =
nullptr;
329 _hasWrittenToOuputStream =
false;
332 if (!_outputFileName.empty() && _outputStream==
nullptr) {
333 std::ostringstream fileName;
334 if (_iterationCounter>0) {
335 int leadingZeros = 1;
336 for (
int i=0; i<DigitsInFilenamesIterationNumer-1; i++) {
339 fileName <<
"grid-traversal-" ;
340 while (_iterationCounter < leadingZeros) {
344 fileName << _iterationCounter <<
"-";
346 fileName << _outputFileName;
347 _outputStream =
new std::ofstream( fileName.str().c_str() );
354 if (!outputLogFileName.empty()) {
355 std::ostringstream myOutputFileName;
357 _outputFileName = myOutputFileName.str();
360 _outputFileName = outputLogFileName;
363 _outputFileName = outputLogFileName;
366 reopenOutputStream();
371 const std::string& columnSeparator,
373 bool logTimeStampHumanReadable,
378 const std::string& outputLogFileName
380 _logColumnSeparator = columnSeparator;
381 _logTimeStamp = logTimeStamp;
382 _logTimeStampHumanReadable = logTimeStampHumanReadable;
383 _logMachineName = logMachineName;
384 _logThreadName = logThreadName;
385 _logMessageType = logMessageType;
386 _logTrace = logTrace;
388 setOutputFile( outputLogFileName );
393 return _logColumnSeparator;
398 return _logTimeStamp;
403 return _logTimeStampHumanReadable;
408 return _logMachineName;
413 return _logThreadName;
418 return _logMessageType;
428 _logColumnSeparator = separator;
433 _logTimeStamp = value;
438 _logTimeStampHumanReadable = value;
443 _logMachineName = value;
448 _logThreadName = value;
453 _logMessageType = value;
463 _quitOnError = value;
470 if (_outputStream!=
nullptr) {
471 _outputStream->flush();
472 delete _outputStream;
473 _outputStream =
nullptr;
#define assertion3(expr, param0, param1, param2)
#define assertionEquals2(lhs, rhs, a, b)
#define assertion5(expr, param0, param1, param2, param3, param4)
#define logWarning(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
bool getLogTrace() const
Is public as some analysis frameworks check explicitly whether these features are switched on.
bool getLogTimeStamp() const
Is public as some analysis frameworks check explicitly whether these features are switched on.
void setLogThreadName(bool value=true)
static const std::string::size_type NumberOfIndentSpaces
std::string constructMessageString(std::string messageType, long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
Construct message string.
void reopenOutputStream()
void closeOutputStreamAndReopenNewOne()
The command line logger can pipe debug data into an output file instead of piping everything to the t...
static const std::string::size_type NumberOfStandardColumnSpaces
void setLogTimeStampHumanReadable(bool value=true)
void setLogFormat(const std::string &columnSeparator, bool logTimeStamp, bool logTimeStampHumanReadable, bool logMachineName, bool logThreadName, bool logMessageType, bool logTrace, const std::string &outputLogFileName)
void setLogMachineName(bool value=true)
void setLogColumnSeparator(const std::string &separator=" ")
bool getLogMessageType() const
static CommandLineLogger & getInstance()
void setLogTrace(bool value=true)
void indent(bool indent, const std::string &trace, const std::string &message)
Tells the logger to increment/decrement the indent.
static std::string getTimeStampHumanReadable(long int timestampNanoseconds)
static const int DigitsInFilenamesIterationNumer
void setQuitOnError(bool value)
static const std::string::size_type NumberOfTraceColumnSpaces
The trace column is not formatted using only tabulators, but it uses spaces to create a unique column...
void traceOut(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
std::string getLogColumnSeparator() const
void configureOutputStreams()
Configures the output streams.
static CommandLineLogger _singleton
CommandLineLogger & operator=(const CommandLineLogger &)
Declared private since assignment does not make sense for an output class (output information mismatc...
void debug(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
void error(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
Write Error.
bool getLogMachineName() const
Is public as some analysis frameworks check explicitly whether these features are switched on.
void setOutputFile(const std::string &outputLogFileName)
Is redundant, as you could use setLogFormat() instead.
void traceIn(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
void setLogMessageType(bool value=true)
bool getLogTimeStampHumanReadable() const
void info(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
void setLogTimeStamp(bool value=true)
static std::string::size_type _indent
Indent is supported only in debug mode.
std::string addSeparators(std::string::size_type spaces, std::string message) const
Takes the message and adds spaces such that the entries are aligned like in a table.
void warning(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
Write Warning.
bool getLogThreadName() const
Is public as some analysis frameworks check explicitly whether these features are switched on.
CommandLineLogger()
It's a singleton.
static Rank & getInstance()
This operation returns the singleton instance.
int getRank() const
Return rank of this node.
static void abort(int errorCode)
A proper abort in an MPI context has to use MPI_Abort.
static Core & getInstance()
Create a lock around a boolean semaphore region.
static const std::string TargetDebug
static const std::string TargetInfo
static const std::string TargetWarning