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 <folly/Range.h>
21 #include <folly/experimental/logging/LogConfig.h>
24 * This file contains utility functions for parsing and serializing
27 * This is separate from the LogConfig class itself, to reduce the dependencies
28 * of the core logging library. Other code that wants to use the logging
29 * library to log messages but does not need to parse log config strings
30 * therefore does not need to depend on the folly JSON library.
37 class LogConfigParseError : public std::invalid_argument {
39 using std::invalid_argument::invalid_argument;
43 * Parse a log configuration string.
45 * See the documentation in logging/docs/Config.md for a description of the
46 * configuration string syntax.
48 * Throws a LogConfigParseError on error.
50 LogConfig parseLogConfig(StringPiece value);
53 * Parse a JSON configuration string.
55 * See the documentation in logging/docs/Config.md for a description of the
56 * JSON configuration object format.
58 * This function uses relaxed JSON parsing, allowing C and C++ style
59 * comments, as well as trailing commas.
61 LogConfig parseLogConfigJson(StringPiece value);
64 * Parse a folly::dynamic object.
66 * The input should be an object data type, and is parsed the same as a JSON
67 * object accpted by parseLogConfigJson().
69 LogConfig parseLogConfigDynamic(const dynamic& value);
72 * Convert a LogConfig object to a folly::dynamic object.
74 * This can be used to serialize it as a JSON string, which can later be read
75 * back using parseLogConfigJson().
77 dynamic logConfigToDynamic(const LogConfig& config);
78 dynamic logConfigToDynamic(const LogHandlerConfig& config);
79 dynamic logConfigToDynamic(const LogCategoryConfig& config);