proxygen
StreamHandlerFactory.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/Conv.h>
22 
23 namespace folly {
24 
27  public:
29  if (name == "stream") {
30  stream_ = value.str();
31  return true;
32  }
33  return fileWriterFactory_.processOption(name, value);
34  }
35 
36  std::shared_ptr<LogWriter> createWriter() override {
37  // Get the output file to use
38  File outputFile;
39  if (stream_.empty()) {
40  throw std::invalid_argument(
41  "no stream name specified for stream handler");
42  } else if (stream_ == "stderr") {
43  outputFile = File{STDERR_FILENO, /* ownsFd */ false};
44  } else if (stream_ == "stdout") {
45  outputFile = File{STDOUT_FILENO, /* ownsFd */ false};
46  } else {
47  throw std::invalid_argument(to<std::string>(
48  "unknown stream \"",
49  stream_,
50  "\": expected one of stdout or stderr"));
51  }
52 
53  return fileWriterFactory_.createWriter(std::move(outputFile));
54  }
55 
58 };
59 
60 std::shared_ptr<LogHandler> StreamHandlerFactory::createHandler(
61  const Options& options) {
62  WriterFactory writerFactory;
64  getType(), &writerFactory, options);
65 }
66 
67 } // namespace folly
std::string str() const
Definition: Range.h:591
static std::shared_ptr< StandardLogHandler > createHandler(StringPiece type, WriterFactory *writerFactory, const Options &options)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
bool processOption(StringPiece name, StringPiece value)
std::shared_ptr< LogHandler > createHandler(const Options &options) override
const char * name
Definition: http_parser.c:437
bool processOption(StringPiece name, StringPiece value) override
StringPiece getType() const override
const char * string
Definition: Conv.cpp:212
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
std::shared_ptr< LogWriter > createWriter() override
std::shared_ptr< LogWriter > createWriter(File file)
std::unordered_map< std::string, std::string > Options