2 * Copyright 2017-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.
19 #include <unordered_map>
21 #include <folly/experimental/logging/LogCategoryConfig.h>
22 #include <folly/experimental/logging/LogHandlerConfig.h>
27 * LogConfig contains configuration for the LoggerDB.
29 * This includes information about the log levels for log categories,
30 * as well as what log handlers are configured and which categories they are
35 using CategoryConfigMap = std::unordered_map<std::string, LogCategoryConfig>;
36 using HandlerConfigMap = std::unordered_map<std::string, LogHandlerConfig>;
38 LogConfig() = default;
40 HandlerConfigMap handlerConfigs,
41 CategoryConfigMap catConfigs)
42 : handlerConfigs_{std::move(handlerConfigs)},
43 categoryConfigs_{std::move(catConfigs)} {}
45 const CategoryConfigMap& getCategoryConfigs() const {
46 return categoryConfigs_;
48 const HandlerConfigMap& getHandlerConfigs() const {
49 return handlerConfigs_;
52 bool operator==(const LogConfig& other) const;
53 bool operator!=(const LogConfig& other) const;
56 * Update this LogConfig object by merging in settings from another
59 * All LogHandler settings from the other LogConfig will be inserted into
60 * this LogConfig. If a log handler with the same name was already defined
61 * in this LogConfig it will be replaced with the new settings.
63 * All LogCategory settings from the other LogConfig will be inserted into
64 * this LogConfig. If a log category with the same name was already defined
65 * in this LogConfig, its settings will be updated with settings from the
66 * other LogConfig. However, if the other LogConfig does not define handler
67 * settings for the category it will retain its current handler settings.
69 * This method allows LogConfig objects to be combined before applying them.
70 * Using LogConfig::update() will produce the same results as if
71 * LoggerDB::updateConfig() had been called with both configs sequentially.
72 * In other words, this operation:
74 * configA.update(configB);
75 * loggerDB.updateConfig(configA);
77 * will produce the same results as:
79 * loggerDB.updateConfig(configA);
80 * loggerDB.updateConfig(configA);
82 void update(const LogConfig& other);
85 HandlerConfigMap handlerConfigs_;
86 CategoryConfigMap categoryConfigs_;