12#define _FORMAT(_fmt, ...) \
13 ([&](void) -> std::string { \
14 int _sz = std::snprintf(nullptr, 0, _fmt, __VA_ARGS__); \
15 std::vector<char> _out(_sz + 1); \
16 std::snprintf(&_out[0], _out.size(), _fmt, __VA_ARGS__); \
17 return std::string(_out.data()); \
23 LogBuffer(std::streambuf *log_, std::streambuf *out_)
32 int const logPut(
log->sputc(c));
33 int const outPut(
out->sputc(c));
34 return logPut == EOF || outPut == EOF ? EOF : c;
39 int const logSync(
log->pubsync());
40 int const outSync(
out->pubsync());
41 return logSync == 0 && outSync == 0 ? 0 : -1;
50 std::string
const &
indent =
"\t");
52 std::ostream &
prepare(
int const rank,
53 std::string
const &sourceFileName,
55 std::string
const &category =
"");
108 if (sisi4s::Log::getRank() != 0) { \
111 if (sisi4s::Log::getRank() != 0) { \
112 } else std::cout << "WARNING: "
113#define NEW_FILE(NAME) \
114 if (sisi4s::Log::getRank() != 0) { \
115 } else std::ofstream(NAME, std::ofstream::out)
117 if (sisi4s::Log::getRank() != 0) { \
118 } else std::ofstream(NAME, std::ofstream::app)
120 if (sisi4s::Log::getRank() != 0) { \
121 } else sisi4s::Log::getLogStream().prepare(0, __FILE__, __VA_ARGS__)
122#define LOG_RANK(...) \
123 sisi4s::Log::getLogStream().prepare(sisi4s::Log::getRank(), \
LogBuffer(std::streambuf *log_, std::streambuf *out_)
Definition Log.hpp:23
virtual int sync()
Definition Log.hpp:38
std::streambuf * log
Definition Log.hpp:43
std::streambuf * out
Definition Log.hpp:43
virtual int overflow(int c)
Definition Log.hpp:28
std::string indent
Indentation string used for each log level. By default a tab character will be used.
Definition Log.hpp:71
int logLevel
The log level to use for subsequent LOG messages. A log message will only be written if its log level...
Definition Log.hpp:66
std::ostream & prepare(int const rank, std::string const &sourceFileName, int const level, std::string const &category="")
Definition Log.cxx:19
std::ofstream logFile
Definition Log.hpp:58
LogBuffer logBuffer
Definition Log.hpp:59
Time startTime
Definition Log.hpp:73
Class with static members offering control over logging. Log entries are created with the macro LOG.
Definition Log.hpp:80
static void setFileName(const std::string &fileName)
Definition Log.cxx:49
static LogStream * logStream
Definition Log.hpp:95
static LogStream & getLogStream()
Definition Log.cxx:57
static int getRank()
Definition Log.cxx:47
static int getLogLevel()
Definition Log.cxx:55
static int logLevel
Definition Log.hpp:94
static void setRank(const int rank)
Definition Log.cxx:45
static void setLogLevel(const int logLevel)
Definition Log.cxx:53
static std::string fileName
Definition Log.hpp:93
static std::string getFileName()
Definition Log.cxx:51
static int rank
Definition Log.hpp:92
Definition Algorithm.hpp:10