Adds writer test case for RCU
[folly.git] / folly / experimental / logging / LogHandlerFactory.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 <memory>
19 #include <string>
20 #include <unordered_map>
21
22 #include <folly/CppAttributes.h>
23 #include <folly/Range.h>
24
25 namespace folly {
26
27 class LogHandler;
28
29 class LogHandlerFactory {
30  public:
31   using Options = std::unordered_map<std::string, std::string>;
32
33   virtual ~LogHandlerFactory() = default;
34
35   /**
36    * Get the type name of this LogHandlerFactory.
37    *
38    * The type field in the LogHandlerConfig for all LogHandlers created by this
39    * factory should match the type of the LogHandlerFactory.
40    *
41    * The type of a LogHandlerFactory should never change.  The returned
42    * StringPiece should be valid for the lifetime of the LogHandlerFactory.
43    */
44   virtual StringPiece getType() const = 0;
45
46   /**
47    * Create a new LogHandler.
48    */
49   virtual std::shared_ptr<LogHandler> createHandler(const Options& options) = 0;
50
51   /**
52    * Update an existing LogHandler with a new configuration.
53    *
54    * This may create a new LogHandler object, or it may update the existing
55    * LogHandler in place.
56    *
57    * The returned pointer will point to the input handler if it was updated in
58    * place, or will point to a new LogHandler if a new one was created.
59    */
60   virtual std::shared_ptr<LogHandler> updateHandler(
61       FOLLY_MAYBE_UNUSED const std::shared_ptr<LogHandler>& existingHandler,
62       const Options& options) {
63     // Subclasses may override this with functionality to update an existing
64     // handler in-place.  However, provide a default implementation that simply
65     // calls createHandler() to always create a new handler object.
66     return createHandler(options);
67   }
68 };
69
70 } // namespace folly