proxygen
folly::LogStreamBuffer Class Reference

#include <LogStream.h>

Inheritance diagram for folly::LogStreamBuffer:

Public Member Functions

 LogStreamBuffer ()
 
bool empty () const
 
std::string extractString ()
 
int_type overflow (int_type ch) override
 

Private Types

enum  : size_t { kInitialCapacity = 256 }
 

Private Attributes

std::string str_
 

Detailed Description

A std::streambuf implementation for use by LogStream

Definition at line 28 of file LogStream.h.

Member Enumeration Documentation

anonymous enum : size_t
private
Enumerator
kInitialCapacity 

Definition at line 48 of file LogStream.h.

Constructor & Destructor Documentation

folly::LogStreamBuffer::LogStreamBuffer ( )
inline

Definition at line 30 of file LogStream.h.

30  {
31  // We intentionally do not reserve any string buffer space initially,
32  // since this will not be needed for XLOG() and XLOGF() statements
33  // that do not use the streaming API. (e.g., XLOG(INFO, "test ", 1234) )
34  }

Member Function Documentation

bool folly::LogStreamBuffer::empty ( ) const
inline

Definition at line 36 of file LogStream.h.

References str_.

36  {
37  return str_.empty();
38  }
std::string str_
Definition: LogStream.h:49
std::string folly::LogStreamBuffer::extractString ( )
inline

Definition at line 40 of file LogStream.h.

References ch, folly::gen::move, overflow(), and str_.

40  {
41  str_.resize(pptr() - (&str_.front()));
42  return std::move(str_);
43  }
std::string str_
Definition: LogStream.h:49
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
LogStreamBuffer::int_type folly::LogStreamBuffer::overflow ( int_type  ch)
override

Definition at line 20 of file LogStream.cpp.

References ch, kInitialCapacity, and str_.

Referenced by extractString().

20  {
21  auto currentSize = str_.size();
22  size_t newSize;
23  if (currentSize == 0) {
24  newSize = kInitialCapacity;
25  } else {
26  // Increase by 1.25 each time
27  newSize = currentSize + (currentSize >> 2);
28  }
29 
30  try {
31  str_.resize(newSize);
32 
33  if (ch == EOF) {
34  setp((&str_.front()) + currentSize, (&str_.front()) + newSize);
35  return 'x';
36  } else {
37  str_[currentSize] = static_cast<char>(ch);
38  setp((&str_.front()) + currentSize + 1, (&str_.front()) + newSize);
39  return ch;
40  }
41  } catch (const std::exception&) {
42  // Return EOF to indicate that the operation failed.
43  // In general the only exception we really expect to see here is
44  // std::bad_alloc() from the str_.resize() call.
45  return EOF;
46  }
47 }
std::string str_
Definition: LogStream.h:49
auto ch

Member Data Documentation

std::string folly::LogStreamBuffer::str_
private

Definition at line 49 of file LogStream.h.

Referenced by empty(), extractString(), and overflow().


The documentation for this class was generated from the following files: