Skip to content

Commit

Permalink
Throw RegexParseException after failed nginx log match
Browse files Browse the repository at this point in the history
Fixed #3
  • Loading branch information
htfy96 committed Sep 23, 2016
1 parent 889ddc3 commit a9feac0
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions watcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <vector>
#include <map>
#include <regex>
#include <stdexcept>
#include <cmath>
#include <iomanip>
#include <sstream>
Expand Down Expand Up @@ -192,6 +193,14 @@ struct NginxLogEntry
std::string type;
};

class RegexParseException: public std::runtime_error
{
public:
RegexParseException(const std::string &o):
std::runtime_error(std::string("Failed to match Regex! Original: ") + o)
{}
};


class NginxLogEntryParser
{
Expand Down Expand Up @@ -220,8 +229,10 @@ class NginxLogEntryParser


} else
std::cout << "Not found!" << std::endl;
return NginxLogEntry();
{
throw RegexParseException(s);
}

}
};

Expand Down Expand Up @@ -432,7 +443,15 @@ int main(int argc, char* argv[])
s.checkAndAddMem(mg.getMemInfo());
auto newEntrys = nl.getIncrLines();
for (const auto & item :newEntrys)
s.checkAndAddNginxInfos(np.parse(item));
{
try
{
s.checkAndAddNginxInfos(np.parse(item));
} catch (const RegexParseException& e)
{
std::cerr << e.what() << std::endl;
}
}
s.updateDiskSpace(dg.getDiskSpace());
std::ofstream of(argv[4]);
printJSON(of, s);
Expand Down

0 comments on commit a9feac0

Please sign in to comment.