24 logError(
"interpretTokens(...)",
"expected \"debug\", \"info\", \"all\" or \"trace\" but got " << levelToken );
28 int rank = rankToken==
"-1" ? -1 : atoi( rankToken.c_str() );
30 logError(
"interpretTokens(...)",
"expected positive rank or -1 for all ranks but got " << rankToken );
34 bool isFilter = onOffToken==
"black";
35 if (onOffToken.compare(
"black")!=0 && onOffToken.compare(
"white")!=0) {
36 logError(
"interpretTokens(...)",
"expected \"black\" or \"white\" but got \"" << onOffToken <<
"\"");
42 levelToken, rank, classNameToken, isFilter,
52 std::string lineWithNewline = line +
'\n';
55 int characterPosition = 0;
56 const int NumberOfTokensPerLine = 5;
57 std::string tokens[NumberOfTokensPerLine];
59 while (currentToken<NumberOfTokensPerLine && !file.eof() && characterPosition <
static_cast<int>(lineWithNewline.length())) {
60 char buffer = lineWithNewline[characterPosition];
62 const bool bufferIsWhiteSpace =
67 if (bufferIsWhiteSpace && !tokens[currentToken].empty()) {
70 if (!bufferIsWhiteSpace) {
71 tokens[currentToken] += buffer;
77 if (currentToken == NumberOfTokensPerLine-1) {
83 if (currentToken != NumberOfTokensPerLine) {
84 logError(
"parsePlainTextFile(string)",
"syntax error in input file " << filename <<
", line " << linenumber <<
":" << line );
87 bool result = interpretTokens(tokens[0],tokens[1],tokens[2],tokens[3],tokens[4]);
89 logError(
"parsePlainTextFile(string)",
"syntax error in input file " << filename <<
", line " << linenumber <<
":" << line );
96 std::size_t first = line.find_first_not_of(
' ');
97 if (first == std::string::npos)
99 std::size_t last = line.find_last_not_of(
' ');
100 return line.substr(first, (last-first+1));
117 file.open(filename.c_str());
119 logWarning(
"parsePlainTextFile(string)",
"was not able to open input file " << filename );
125 while (!file.eof() && result) {
126 std::getline(file, line);
127 line = trimLine(line);
128 if(line.length() > 0 && line[0]!=
'#') {
129 result = parseLine(file, filename, line, linenumber);
136 logWarning(
"parsePlainTextFile(string)",
"filter file " << filename <<
" was invalid. Switch on all log statements" );
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
#define logWarning(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
static std::string trimLine(const std::string &line)
static bool parsePlainTextFile(const std::string &filename)
Tries to parse a simple text file where each line contains an entry.
static bool interpretTokens(const std::string &levelToken, const std::string &classNameToken, const std::string &rankToken, const std::string &onOffToken, const std::string &phaseToken)
static bool parseLine(std::ifstream &file, const std::string &filename, const std::string &line, int linenumber)
static tarch::logging::Log _log
void addFilterListEntry(const FilterListEntry &entry)
Add one filter list entry.
static LogFilter & getInstance()
Represents one entry of the filter list.
static const std::string TargetTrace
static const std::string TargetDebug
static const std::string TargetInfo
static const bool WhiteListEntry
static const std::string TargetAll
static const std::string AlwaysOn