99#include " basic_db.h"
1010#include " core/db_factory.h"
1111
12- using std::cout;
13- using std::endl;
12+ namespace {
13+ const std::string PROP_SILENT = " basic.silent" ;
14+ const std::string PROP_SILENT_DEFAULT = " false" ;
15+ }
1416
1517namespace ycsbc {
1618
1719std::mutex BasicDB:: mutex_;
1820
1921void BasicDB::Init () {
2022 std::lock_guard<std::mutex> lock (mutex_);
23+ if (props_->GetProperty (PROP_SILENT , PROP_SILENT_DEFAULT ) == " true" ) {
24+ out_ = new std::ofstream;
25+ out_->setstate (std::ios_base::badbit);
26+ } else {
27+ out_ = &std::cout;
28+ }
2129}
2230
2331DB ::Status BasicDB::Read (const std::string &table, const std::string &key,
2432 const std::vector<std::string> *fields, std::vector<Field> &result) {
2533 std::lock_guard<std::mutex> lock (mutex_);
26- cout << " READ " << table << ' ' << key;
34+ *out_ << " READ " << table << ' ' << key;
2735 if (fields) {
28- cout << " [ " ;
36+ *out_ << " [ " ;
2937 for (auto f : *fields) {
30- cout << f << ' ' ;
38+ *out_ << f << ' ' ;
3139 }
32- cout << ' ]' << endl;
40+ *out_ << ' ]' << std:: endl;
3341 } else {
34- cout << " < all fields >" << endl;
42+ *out_ << " < all fields >" << std:: endl;
3543 }
3644 return kOK ;
3745}
@@ -40,44 +48,44 @@ DB::Status BasicDB::Scan(const std::string &table, const std::string &key, int l
4048 const std::vector<std::string> *fields,
4149 std::vector<std::vector<Field>> &result) {
4250 std::lock_guard<std::mutex> lock (mutex_);
43- cout << " SCAN " << table << ' ' << key << " " << len;
51+ *out_ << " SCAN " << table << ' ' << key << " " << len;
4452 if (fields) {
45- cout << " [ " ;
53+ *out_ << " [ " ;
4654 for (auto f : *fields) {
47- cout << f << ' ' ;
55+ *out_ << f << ' ' ;
4856 }
49- cout << ' ]' << endl;
57+ *out_ << ' ]' << std:: endl;
5058 } else {
51- cout << " < all fields >" << endl;
59+ *out_ << " < all fields >" << std:: endl;
5260 }
5361 return kOK ;
5462}
5563
5664DB ::Status BasicDB::Update (const std::string &table, const std::string &key,
5765 std::vector<Field> &values) {
5866 std::lock_guard<std::mutex> lock (mutex_);
59- cout << " UPDATE " << table << ' ' << key << " [ " ;
67+ *out_ << " UPDATE " << table << ' ' << key << " [ " ;
6068 for (auto v : values) {
61- cout << v.name << ' =' << v.value << ' ' ;
69+ *out_ << v.name << ' =' << v.value << ' ' ;
6270 }
63- cout << ' ]' << endl;
71+ *out_ << ' ]' << std:: endl;
6472 return kOK ;
6573}
6674
6775DB ::Status BasicDB::Insert (const std::string &table, const std::string &key,
6876 std::vector<Field> &values) {
6977 std::lock_guard<std::mutex> lock (mutex_);
70- cout << " INSERT " << table << ' ' << key << " [ " ;
78+ *out_ << " INSERT " << table << ' ' << key << " [ " ;
7179 for (auto v : values) {
72- cout << v.name << ' =' << v.value << ' ' ;
80+ *out_ << v.name << ' =' << v.value << ' ' ;
7381 }
74- cout << ' ]' << endl;
82+ *out_ << ' ]' << std:: endl;
7583 return kOK ;
7684}
7785
7886DB ::Status BasicDB::Delete (const std::string &table, const std::string &key) {
7987 std::lock_guard<std::mutex> lock (mutex_);
80- cout << " DELETE " << table << ' ' << key << endl;
88+ *out_ << " DELETE " << table << ' ' << key << std:: endl;
8189 return kOK ;
8290}
8391
0 commit comments