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.
20 #include <unordered_map>
22 #include <folly/CppAttributes.h>
23 #include <folly/Range.h>
29 class LogHandlerFactory {
31 using Options = std::unordered_map<std::string, std::string>;
33 virtual ~LogHandlerFactory() = default;
36 * Get the type name of this LogHandlerFactory.
38 * The type field in the LogHandlerConfig for all LogHandlers created by this
39 * factory should match the type of the LogHandlerFactory.
41 * The type of a LogHandlerFactory should never change. The returned
42 * StringPiece should be valid for the lifetime of the LogHandlerFactory.
44 virtual StringPiece getType() const = 0;
47 * Create a new LogHandler.
49 virtual std::shared_ptr<LogHandler> createHandler(const Options& options) = 0;
52 * Update an existing LogHandler with a new configuration.
54 * This may create a new LogHandler object, or it may update the existing
55 * LogHandler in place.
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.
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);