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.
16 #include <folly/experimental/logging/LogStream.h>
20 LogStreamBuffer::int_type LogStreamBuffer::overflow(int_type ch) {
21 auto currentSize = str_.size();
23 if (currentSize == 0) {
24 newSize = kInitialCapacity;
26 // Increase by 1.25 each time
27 newSize = currentSize + (currentSize >> 2);
34 setp((&str_.front()) + currentSize, (&str_.front()) + newSize);
37 str_[currentSize] = static_cast<char>(ch);
38 setp((&str_.front()) + currentSize + 1, (&str_.front()) + newSize);
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.
49 LogStream::LogStream(LogStreamProcessor* processor)
50 : std::ostream(nullptr), processor_{processor} {
54 LogStream::~LogStream() {}