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/ImmediateFileWriter.h>
18 #include <folly/FileUtil.h>
19 #include <folly/String.h>
20 #include <folly/experimental/logging/LoggerDB.h>
22 using folly::StringPiece;
26 ImmediateFileWriter::ImmediateFileWriter(StringPiece path)
27 : file_{path.str(), O_WRONLY | O_APPEND | O_CREAT} {}
29 ImmediateFileWriter::ImmediateFileWriter(folly::File&& file)
30 : file_{std::move(file)} {}
32 void ImmediateFileWriter::writeMessage(
34 uint32_t /* flags */) {
36 // We are doing direct file descriptor writes here, so there is no buffering
37 // of log message data. Each message is immediately written to the output.
38 auto ret = folly::writeFull(file_.fd(), buffer.data(), buffer.size());
41 LoggerDB::internalWarning(
44 "error writing to log file ",
51 void ImmediateFileWriter::flush() {}