Fix copyright lines
[folly.git] / folly / experimental / logging / StandardLogHandlerFactory.h
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  */
16 #pragma once
17
18 #include <string>
19 #include <unordered_map>
20
21 #include <folly/Range.h>
22
23 namespace folly {
24
25 class LogWriter;
26 class LogFormatter;
27 class StandardLogHandler;
28
29 /**
30  * StandardLogHandlerFactory contains helper methods for LogHandlerFactory
31  * implementations that create StandardLogHandler objects.
32  *
33  * StandardLogHandlerFactory does not derive from LogHandlerFactory itself.
34  */
35 class StandardLogHandlerFactory {
36  public:
37   using Options = std::unordered_map<std::string, std::string>;
38
39   class OptionProcessor {
40    public:
41     virtual ~OptionProcessor() {}
42
43     /**
44      * Process an option.
45      *
46      * This should return true if the option was processed successfully,
47      * or false if this is an unknown option name.  It should throw an
48      * exception if the option name is known but there is a problem with the
49      * value.
50      */
51     virtual bool processOption(StringPiece name, StringPiece value) = 0;
52   };
53
54   class FormatterFactory : public OptionProcessor {
55    public:
56     virtual std::shared_ptr<LogFormatter> createFormatter() = 0;
57   };
58
59   class WriterFactory : public OptionProcessor {
60    public:
61     virtual std::shared_ptr<LogWriter> createWriter() = 0;
62   };
63
64   static std::shared_ptr<StandardLogHandler> createHandler(
65       StringPiece type,
66       WriterFactory* writerFactory,
67       const Options& options);
68 };
69
70 } // namespace folly