@ -15,11 +15,11 @@
namespace rocksdb {
namespace rocksdb {
// JSONWritt er 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 JSONWritt er {
class JSONWriter {
public :
public :
JSONWritt er ( ) : 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 ( ) ; }
JSONWritt er & 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 ;
}
}
JSONWritt er & 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 >
JSONWritt er & 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 JSONWritt erState {
enum JSONWriterState {
kExpectKey ,
kExpectKey ,
kExpectValue ,
kExpectValue ,
kInArray ,
kInArray ,
} ;
} ;
JSONWritt erState 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_writt er_ < < val ;
* json_writer_ < < val ;
return * this ;
return * this ;
}
}
void StartArray ( ) { json_writt er_ - > StartArray ( ) ; }
void StartArray ( ) { json_writer_ - > StartArray ( ) ; }
void EndArray ( ) { json_writt er_ - > EndArray ( ) ; }
void EndArray ( ) { json_writer_ - > EndArray ( ) ; }
void StartObject ( ) { json_writt er_ - > StartObject ( ) ; }
void StartObject ( ) { json_writer_ - > StartObject ( ) ; }
void EndObject ( ) { json_writt er_ - > EndObject ( ) ; }
void EndObject ( ) { json_writer_ - > EndObject ( ) ; }
~ EventLoggerStream ( ) ;
~ EventLoggerStream ( ) ;
private :
private :
void MakeStream ( ) {
void MakeStream ( ) {
if ( ! json_writt er_ ) {
if ( ! json_writer_ ) {
json_writt er_ = new JSONWrit ter ( ) ;
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
JSONWritt er * json_writ ter_ ;
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: