Fix copyright lines
[folly.git] / folly / experimental / logging / LogConfigParser.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 <stdexcept>
19
20 #include <folly/CPortability.h>
21 #include <folly/Range.h>
22 #include <folly/experimental/logging/LogConfig.h>
23
24 /*
25  * This file contains utility functions for parsing and serializing
26  * LogConfig strings.
27  *
28  * This is separate from the LogConfig class itself, to reduce the dependencies
29  * of the core logging library.  Other code that wants to use the logging
30  * library to log messages but does not need to parse log config strings
31  * therefore does not need to depend on the folly JSON library.
32  */
33
34 namespace folly {
35
36 struct dynamic;
37
38 class FOLLY_EXPORT LogConfigParseError : public std::invalid_argument {
39  public:
40   using std::invalid_argument::invalid_argument;
41 };
42
43 /**
44  * Parse a log configuration string.
45  *
46  * See the documentation in logging/docs/Config.md for a description of the
47  * configuration string syntax.
48  *
49  * Throws a LogConfigParseError on error.
50  */
51 LogConfig parseLogConfig(StringPiece value);
52
53 /**
54  * Parse a JSON configuration string.
55  *
56  * See the documentation in logging/docs/Config.md for a description of the
57  * JSON configuration object format.
58  *
59  * This function uses relaxed JSON parsing, allowing C and C++ style
60  * comments, as well as trailing commas.
61  */
62 LogConfig parseLogConfigJson(StringPiece value);
63
64 /**
65  * Parse a folly::dynamic object.
66  *
67  * The input should be an object data type, and is parsed the same as a JSON
68  * object accpted by parseLogConfigJson().
69  */
70 LogConfig parseLogConfigDynamic(const dynamic& value);
71
72 /**
73  * Convert a LogConfig object to a folly::dynamic object.
74  *
75  * This can be used to serialize it as a JSON string, which can later be read
76  * back using parseLogConfigJson().
77  */
78 dynamic logConfigToDynamic(const LogConfig& config);
79 dynamic logConfigToDynamic(const LogHandlerConfig& config);
80 dynamic logConfigToDynamic(const LogCategoryConfig& config);
81
82 } // namespace folly