1 // Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef DHCPSRV_LOGGING_H
8 #define DHCPSRV_LOGGING_H
9 
10 #include <cc/data.h>
11 #include <process/logging_info.h>
12 #include <process/config_base.h>
13 #include <vector>
14 
15 namespace isc {
16 namespace process {
17 
18 /// @brief Configures log4cplus by translating Kea configuration structures
19 ///
20 /// This parser iterates over provided data elements and translates them
21 /// into values applicable to log4cplus.
22 ///
23 /// The data structures converted to JSON format have the following syntax:
24 /// {
25 ///     "name": "kea",
26 ///     "output_options": [
27 ///         {
28 ///             "output": "/home/thomson/kea-inst/kea-warn.log",
29 ///             "maxver": 8,
30 ///             "maxsize": 204800,
31 ///             "flush": true
32 ///         }
33 ///     ],
34 ///     "severity": "WARN"
35 /// }
36 ///
37 /// This is only an example and actual values may be different.
38 ///
39 /// The data structures don't have to originate from JSON. JSON is just a
40 /// convenient presentation syntax.
41 ///
42 /// This class uses @c ConfigBase object to store logging configuration.
43 class LogConfigParser {
44 public:
45 
46     /// @brief Constructor
47     ///
48     /// @param storage parsed logging configuration will be stored here
49     LogConfigParser(const ConfigPtr& storage);
50 
51     /// @brief Parses specified configuration
52     ///
53     /// Walks over specified logging configuration JSON structures and store
54     /// parsed information in config_->logging_info_.
55     ///
56     /// @param log_config JSON structures to be parsed (loggers list)
57     /// @param verbose specifies verbose mode (true forces DEBUG, debuglevel = 99)
58     void parseConfiguration(const isc::data::ConstElementPtr& log_config,
59                             bool verbose = false);
60 
61 private:
62 
63     /// @brief Parses one JSON structure in Server/loggers" array
64     ///
65     /// @param entry JSON structure to be parsed
66     /// @brief parses one structure in Server/loggers.
67     void parseConfigEntry(isc::data::ConstElementPtr entry);
68 
69     /// @brief Parses output_options structure
70     ///
71     /// @ref @c LogConfigParser for an example in JSON format.
72     ///
73     /// @param destination parsed parameters will be stored here
74     /// @param output_options element to be parsed
75     void parseOutputOptions(std::vector<LoggingDestination>& destination,
76                             isc::data::ConstElementPtr output_options);
77 
78     /// @brief Configuration is stored here
79     ///
80     /// LogConfigParser class uses only config_->logging_info_ field.
81     ConfigPtr config_;
82 
83     /// @brief Verbose mode
84     ///
85     /// When verbose mode is enabled, logging severity is overridden to DEBUG,
86     /// and debuglevel is always 99.
87     bool verbose_;
88 };
89 
90 } // namespace isc::dhcp
91 } // namespace isc
92 
93 #endif // DHCPSRV_LOGGING_H
94