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/FileHandlerFactory.h>
18 #include <folly/experimental/logging/FileWriterFactory.h>
19 #include <folly/experimental/logging/StandardLogHandler.h>
20 #include <folly/experimental/logging/StandardLogHandlerFactory.h>
24 class FileHandlerFactory::WriterFactory
25 : public StandardLogHandlerFactory::WriterFactory {
27 bool processOption(StringPiece name, StringPiece value) override {
33 // TODO: In the future it would be nice to support log rotation, and
34 // add parameters to control when the log file should be rotated.
36 return fileWriterFactory_.processOption(name, value);
39 std::shared_ptr<LogWriter> createWriter() override {
40 // Get the output file to use
42 throw std::invalid_argument("no path specified for file handler");
44 return fileWriterFactory_.createWriter(
45 File{path_, O_WRONLY | O_APPEND | O_CREAT});
49 FileWriterFactory fileWriterFactory_;
52 std::shared_ptr<LogHandler> FileHandlerFactory::createHandler(
53 const Options& options) {
54 WriterFactory writerFactory;
55 return StandardLogHandlerFactory::createHandler(
56 getType(), &writerFactory, options);