proxygen
ImmediateFileWriter.cpp
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  */
17 
18 #include <folly/FileUtil.h>
19 #include <folly/String.h>
20 #include <folly/logging/LoggerDB.h>
22 
23 using folly::StringPiece;
24 
25 namespace folly {
26 
28  : file_{path.str(), O_WRONLY | O_APPEND | O_CREAT} {}
29 
31  : file_{std::move(file)} {}
32 
35  uint32_t /* flags */) {
36  // Write the data.
37  // We are doing direct file descriptor writes here, so there is no buffering
38  // of log message data. Each message is immediately written to the output.
39  auto ret = folly::writeFull(file_.fd(), buffer.data(), buffer.size());
40  if (ret < 0) {
41  int errnum = errno;
43  __FILE__,
44  __LINE__,
45  "error writing to log file ",
46  file_.fd(),
47  ": ",
48  errnoStr(errnum));
49  }
50 }
51 
53 } // namespace folly
std::vector< uint8_t > buffer(kBufferSize+16)
std::string str() const
Definition: Range.h:591
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr size_type size() const
Definition: Range.h:431
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
int fd() const
Definition: File.h:85
ImmediateFileWriter(folly::StringPiece path)
constexpr Iter data() const
Definition: Range.h:446
ssize_t writeFull(int fd, const void *buf, size_t count)
Definition: FileUtil.cpp:134
void writeMessage(folly::StringPiece buffer, uint32_t flags=0) override
fbstring errnoStr(int err)
Definition: String.cpp:463
Range< const char * > StringPiece
static void internalWarning(folly::StringPiece file, int lineNumber, Args &&...args) noexcept
Definition: LoggerDB.h:201