Rename JSONWritter to JSONWriter

Summary: Rename JSONWritter to JSONWriter

Test Plan: make

Reviewers: igor

Reviewed By: igor

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D38733
main
Yueh-Hsuan Chiang 10 years ago
parent 812c461c96
commit d1a978ae3d
  1. 16
      util/event_logger.cc
  2. 32
      util/event_logger.h

@ -21,25 +21,25 @@ namespace rocksdb {
const char* kEventLoggerPrefix = "EVENT_LOG_v1"; const char* kEventLoggerPrefix = "EVENT_LOG_v1";
EventLoggerStream::EventLoggerStream(Logger* logger) EventLoggerStream::EventLoggerStream(Logger* logger)
: logger_(logger), log_buffer_(nullptr), json_writter_(nullptr) {} : logger_(logger), log_buffer_(nullptr), json_writer_(nullptr) {}
EventLoggerStream::EventLoggerStream(LogBuffer* log_buffer) EventLoggerStream::EventLoggerStream(LogBuffer* log_buffer)
: logger_(nullptr), log_buffer_(log_buffer), json_writter_(nullptr) {} : logger_(nullptr), log_buffer_(log_buffer), json_writer_(nullptr) {}
EventLoggerStream::~EventLoggerStream() { EventLoggerStream::~EventLoggerStream() {
if (json_writter_) { if (json_writer_) {
json_writter_->EndObject(); json_writer_->EndObject();
#ifdef ROCKSDB_PRINT_EVENTS_TO_STDOUT #ifdef ROCKSDB_PRINT_EVENTS_TO_STDOUT
printf("%s\n", json_writter_->Get().c_str()); printf("%s\n", json_writer_->Get().c_str());
#else #else
if (logger_) { if (logger_) {
Log(logger_, "%s %s", kEventLoggerPrefix, json_writter_->Get().c_str()); Log(logger_, "%s %s", kEventLoggerPrefix, json_writer_->Get().c_str());
} else if (log_buffer_) { } else if (log_buffer_) {
LogToBuffer(log_buffer_, "%s %s", kEventLoggerPrefix, LogToBuffer(log_buffer_, "%s %s", kEventLoggerPrefix,
json_writter_->Get().c_str()); json_writer_->Get().c_str());
} }
#endif #endif
delete json_writter_; delete json_writer_;
} }
} }

@ -15,11 +15,11 @@
namespace rocksdb { namespace rocksdb {
// JSONWritter doesn't support objects in arrays yet. There wasn't a need for // JSONWriter doesn't support objects in arrays yet. There wasn't a need for
// that. // that.
class JSONWritter { class JSONWriter {
public: public:
JSONWritter() : state_(kExpectKey), first_element_(true) { stream_ << "{"; } JSONWriter() : state_(kExpectKey), first_element_(true) { stream_ << "{"; }
void AddKey(const std::string& key) { void AddKey(const std::string& key) {
assert(state_ == kExpectKey); assert(state_ == kExpectKey);
@ -85,7 +85,7 @@ class JSONWritter {
std::string Get() const { return stream_.str(); } std::string Get() const { return stream_.str(); }
JSONWritter& operator<<(const char* val) { JSONWriter& operator<<(const char* val) {
if (state_ == kExpectKey) { if (state_ == kExpectKey) {
AddKey(val); AddKey(val);
} else { } else {
@ -94,24 +94,24 @@ class JSONWritter {
return *this; return *this;
} }
JSONWritter& operator<<(const std::string& val) { JSONWriter& operator<<(const std::string& val) {
return *this << val.c_str(); return *this << val.c_str();
} }
template <typename T> template <typename T>
JSONWritter& operator<<(const T& val) { JSONWriter& operator<<(const T& val) {
assert(state_ != kExpectKey); assert(state_ != kExpectKey);
AddValue(val); AddValue(val);
return *this; return *this;
} }
private: private:
enum JSONWritterState { enum JSONWriterState {
kExpectKey, kExpectKey,
kExpectValue, kExpectValue,
kInArray, kInArray,
}; };
JSONWritterState state_; JSONWriterState state_;
bool first_element_; bool first_element_;
std::ostringstream stream_; std::ostringstream stream_;
}; };
@ -121,21 +121,21 @@ class EventLoggerStream {
template <typename T> template <typename T>
EventLoggerStream& operator<<(const T& val) { EventLoggerStream& operator<<(const T& val) {
MakeStream(); MakeStream();
*json_writter_ << val; *json_writer_ << val;
return *this; return *this;
} }
void StartArray() { json_writter_->StartArray(); } void StartArray() { json_writer_->StartArray(); }
void EndArray() { json_writter_->EndArray(); } void EndArray() { json_writer_->EndArray(); }
void StartObject() { json_writter_->StartObject(); } void StartObject() { json_writer_->StartObject(); }
void EndObject() { json_writter_->EndObject(); } void EndObject() { json_writer_->EndObject(); }
~EventLoggerStream(); ~EventLoggerStream();
private: private:
void MakeStream() { void MakeStream() {
if (!json_writter_) { if (!json_writer_) {
json_writter_ = new JSONWritter(); json_writer_ = new JSONWriter();
*this << "time_micros" *this << "time_micros"
<< std::chrono::duration_cast<std::chrono::microseconds>( << std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch()).count(); std::chrono::system_clock::now().time_since_epoch()).count();
@ -148,7 +148,7 @@ class EventLoggerStream {
Logger* const logger_; Logger* const logger_;
LogBuffer* const log_buffer_; LogBuffer* const log_buffer_;
// ownership // ownership
JSONWritter* json_writter_; JSONWriter* json_writer_;
}; };
// here is an example of the output that will show up in the LOG: // here is an example of the output that will show up in the LOG:

Loading…
Cancel
Save