Add (smart) logging facility

By means of "Use Debug Log" UCI option it is possible to toggle
the logging of std::cout to file "out.txt" while preserving
the usual output to stdout. There is zero overhead when logging
is disabled and we achieved this without changing a single line
of exsisting code, in particular we still use std::cout as usual.

The idea and part of the code comes from this article:
http://groups.google.com/group/comp.lang.c++/msg/1d941c0f26ea0d81

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2012-03-18 03:20:43 +01:00
parent 2dfc94e0b6
commit eb28a683bd
3 changed files with 68 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ OptionsMap Options; // Global object
namespace {
/// 'On change' actions, triggered by an option's value change
void on_logger(const UCIOption& o) { logger_set(o); }
void on_eval(const UCIOption&) { Eval::init(); }
void on_threads(const UCIOption&) { Threads.read_uci_options(); }
void on_hash_size(const UCIOption& o) { TT.set_size(o); }
@@ -58,6 +59,7 @@ OptionsMap::OptionsMap() {
int msd = cpus < 8 ? 4 : 7;
OptionsMap& o = *this;
o["Use Debug Log"] = UCIOption(false, on_logger);
o["Use Search Log"] = UCIOption(false);
o["Search Log Filename"] = UCIOption("SearchLog.txt");
o["Book File"] = UCIOption("book.bin");