aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorthecharlesblake2017-11-11 12:20:31 +0000
committerthecharlesblake2017-11-11 12:20:31 +0000
commit14f534452ac99913931c0513532dfbad2e277493 (patch)
tree6fa6d5600760a38eff1b75c6b4243d769bde75a6 /src
parentRefactor command line helper (diff)
downloadmetasol-14f534452ac99913931c0513532dfbad2e277493.tar.gz
metasol-14f534452ac99913931c0513532dfbad2e277493.zip

Update logging

Diffstat (limited to 'src')
-rw-r--r--src/main/input-output/command_line_helper.cpp16
-rw-r--r--src/main/input-output/log_helper.h8
-rw-r--r--src/main/main.cpp7
-rw-r--r--src/main/solver/solver.cpp2
4 files changed, 16 insertions, 17 deletions
diff --git a/src/main/input-output/command_line_helper.cpp b/src/main/input-output/command_line_helper.cpp
index 2228d51..b66cc39 100644
--- a/src/main/input-output/command_line_helper.cpp
+++ b/src/main/input-output/command_line_helper.cpp
@@ -4,12 +4,12 @@
#include <tuple>
#include <vector>
-#include <iostream>
#include <boost/program_options.hpp>
#include "command_line_helper.h"
#include "game/sol_rules.h"
+#include "input-output/log_helper.h"
using namespace std;
@@ -43,7 +43,7 @@ bool command_line_helper::parse(int argc, const char* argv[]) {
store(po::command_line_parser(argc, argv).options(cmdline_options)
.positional(p).run(), vm);
} catch(po::error& e) {
- cerr << "Error: " << e.what() << "\n";
+ LOG_ERROR << "Error: " << e.what() << "\n";
return false;
}
@@ -108,34 +108,34 @@ bool command_line_helper::assess_sol_type() {
return true;
} else {
- cerr << "Error: Solitaire type is not valid: " << solitaire_type
+ LOG_ERROR << "Error: Solitaire type is not valid: " << solitaire_type
<< "\nValid solitaire types are: ";
copy(begin(sol_rules::valid_sol_strs), end(sol_rules::valid_sol_strs),
ostream_iterator<string>(cerr, ", "));
- cerr << "\n";
+ LOG_ERROR << "\n";
print_help();
return false;
}
}
void command_line_helper::print_help() {
- cerr << "Usage: solvitaire [options] input-file1 input-file2 ...\n"
+ LOG_ERROR << "Usage: solvitaire [options] input-file1 input-file2 ...\n"
<< main_options << "\n";
}
void command_line_helper::print_no_input_error() {
- cerr << "Error: User must supply input file(s) or the '--random' "
+ LOG_ERROR << "Error: User must supply input file(s) or the '--random' "
"option\n";
print_help();
}
void command_line_helper::print_no_sol_type_error() {
- cerr << "Error: User must supply a solitaire type\n";
+ LOG_ERROR << "Error: User must supply a solitaire type\n";
print_help();
}
void command_line_helper::print_rand_plus_input_err() {
- cerr << "Error: User must supply input file(s) or the '--random' option, "
+ LOG_ERROR << "Error: User must supply input file(s) or the '--random' option, "
"not both\n";
print_help();
}
diff --git a/src/main/input-output/log_helper.h b/src/main/input-output/log_helper.h
index 889a5ae..441381f 100644
--- a/src/main/input-output/log_helper.h
+++ b/src/main/input-output/log_helper.h
@@ -10,10 +10,10 @@
#if defined NDEBUG
#define LOG_DEBUG
#else
- #define LOG_DEBUG(msg) clog << "[debug]\n" << msg
+ #define LOG_DEBUG clog << "[debug]\n"
#endif
-#define LOG_INFO(msg) clog << "[info]\n" << msg
-#define LOG_WARNING(msg) clog << "[warning]\n" << msg
-#define LOG_ERROR(msg) cerr << "[error]\n" << msg
+#define LOG_INFO clog << "[info] "
+#define LOG_WARNING clog << "[warning] "
+#define LOG_ERROR cerr << "[ERROR] "
#endif //SOLVITAIRE_LOG_HELPER_H
diff --git a/src/main/main.cpp b/src/main/main.cpp
index 77d5d5b..803b587 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -1,5 +1,3 @@
-#include <iostream>
-
#include <boost/program_options.hpp>
#include <rapidjson/document.h>
@@ -7,6 +5,7 @@
#include "input-output/deal_parser.h"
#include "game/game_state.h"
#include "solver/solver.h"
+#include "input-output/log_helper.h"
using namespace rapidjson;
@@ -45,7 +44,7 @@ int main(int argc, const char* argv[]) {
}
void solve_random_game(int seed, const sol_rules& rules) {
- cout << "Attempting to solve with seed: " << seed << "...\n";
+ LOG_INFO << "Attempting to solve with seed: " << seed << "...\n";
game_state gs(seed, rules);
solve_game(gs, rules);
}
@@ -59,7 +58,7 @@ void solve_input_files(const vector<string> input_files, const sol_rules rules)
// Creates a game state object from the json, plus a solver
game_state gs(doc);
- cout << "Attempting to solve " << input_json << "...\n";
+ LOG_INFO << "Attempting to solve " << input_json << "...\n";
solve_game(gs, rules);
}
}
diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp
index 1c03d02..ca60333 100644
--- a/src/main/solver/solver.cpp
+++ b/src/main/solver/solver.cpp
@@ -31,7 +31,7 @@ bool solver::run() {
node current = frontier.back();
frontier.pop_back();
- LOG_DEBUG(current.state);
+ LOG_DEBUG << current.state;
// Create new nodes for each of the children
vector<game_state> new_children = current.state.get_next_legal_states();