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.
18 #include <folly/File.h>
19 #include <folly/Range.h>
20 #include <folly/experimental/logging/LogWriter.h>
25 * A LogWriter implementation that immediately writes to a file descriptor when
28 * The downside of this class is that logging I/O occurs directly in your
29 * normal program threads, so that logging I/O may block or slow down normal
32 * However, one benefit of this class is that log messages are written out
33 * immediately, so if your program crashes, all log messages generated before
34 * the crash will have already been written, and no messages will be lost.
36 class ImmediateFileWriter : public LogWriter {
39 * Construct an ImmediateFileWriter that appends to the file at the specified
42 explicit ImmediateFileWriter(folly::StringPiece path);
45 * Construct an ImmediateFileWriter that writes to the specified File object.
47 explicit ImmediateFileWriter(folly::File&& file);
49 using LogWriter::writeMessage;
50 void writeMessage(folly::StringPiece buffer, uint32_t flags = 0) override;
51 void flush() override;
54 ImmediateFileWriter(ImmediateFileWriter const&) = delete;
55 ImmediateFileWriter& operator=(ImmediateFileWriter const&) = delete;