2 * Copyright 2004-present Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <folly/experimental/logging/LogCategory.h>
21 #include <folly/experimental/logging/LogMessage.h>
26 * A std::streambuf implementation for use by LogStream
28 class LogStreamBuffer : public std::streambuf {
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) )
40 std::string extractString() {
41 str_.resize(pptr() - (&str_.front()));
42 return std::move(str_);
45 int_type overflow(int_type ch) override;
48 enum : size_t { kInitialCapacity = 256 };
53 * A std::ostream implementation for use by the logging macros.
55 * All-in-all this is pretty similar to std::stringstream, but lets us
56 * destructively extract an rvalue-reference to the underlying string.
58 class LogStream : public std::ostream {
60 // Explicitly declare the default constructor and destructor, but only
61 // define them in the .cpp file. This prevents them from being inlined at
62 // each FB_LOG() or XLOG() statement. Inlining them just causes extra code
63 // bloat, with minimal benefit--for debug log statements these never even get
64 // called in the common case where the log statement is disabled.
69 return buffer_.empty();
72 std::string extractString() {
73 return buffer_.extractString();
77 LogStreamBuffer buffer_;