proxygen
LogStream.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <ostream>
19 
22 
23 namespace folly {
24 
28 class LogStreamBuffer : public std::streambuf {
29  public:
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  }
35 
36  bool empty() const {
37  return str_.empty();
38  }
39 
41  str_.resize(pptr() - (&str_.front()));
42  return std::move(str_);
43  }
44 
45  int_type overflow(int_type ch) override;
46 
47  private:
48  enum : size_t { kInitialCapacity = 256 };
50 };
51 
52 class LogStreamProcessor;
53 
60 class LogStream : public std::ostream {
61  public:
62  // Explicitly declare the default constructor and destructor, but only
63  // define them in the .cpp file. This prevents them from being inlined at
64  // each FB_LOG() or XLOG() statement. Inlining them just causes extra code
65  // bloat, with minimal benefit--for debug log statements these never even get
66  // called in the common case where the log statement is disabled.
67  explicit LogStream(LogStreamProcessor* processor);
68  ~LogStream();
69 
70  bool empty() const {
71  return buffer_.empty();
72  }
73 
75  return buffer_.extractString();
76  }
77 
79  return processor_;
80  }
81 
82  private:
85 };
86 } // namespace folly
std::string extractString()
Definition: LogStream.h:74
std::string str_
Definition: LogStream.h:49
bool empty() const
Definition: LogStream.h:36
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
int_type overflow(int_type ch) override
Definition: LogStream.cpp:20
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
auto ch
LogStreamProcessor *const processor_
Definition: LogStream.h:84
LogStreamProcessor * getProcessor() const
Definition: LogStream.h:78
const char * string
Definition: Conv.cpp:212
std::unique_ptr< unsigned char[]> buffer_
Definition: Random.cpp:105
LogStreamBuffer buffer_
Definition: LogStream.h:83
bool empty() const
Definition: LogStream.h:70
std::string extractString()
Definition: LogStream.h:40