logging.h 3.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

#ifndef DHCPSRV_LOGGING_H
#define DHCPSRV_LOGGING_H

#include <cc/data.h>
#include <dhcpsrv/configuration.h>
#include <vector>

namespace isc {
namespace dhcp {

Tomek Mrugalski's avatar
Tomek Mrugalski committed
25
/// @brief Configures log4cplus by translating Kea configuration structures
26
///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
27
/// This parser iterates over provided data elements and translates them
28
29
/// into values applicable to log4cplus.
///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/// The data structures converted to JSON format have the following syntax:
/// {
///     "name": "kea",
///     "output_options": [
///         {
///             "output": "/home/thomson/kea-inst/kea-warn.log",
///             "maxver": 8,
///             "maxsize": 204800
///         }
///     ],
///     "severity": "WARN"
/// }
///
/// This is only an example and actual values may be different.
///
/// The data structures don't have to originate from JSON. JSON is just a
/// convenient presentation syntax.
///
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/// This class uses Configuration structure to store logging configuration.
class LogConfigParser {
public:

    /// @brief Constructor
    ///
    /// @param storage parsed logging configuration will be stored here
    LogConfigParser(const ConfigurationPtr& storage);

    /// @brief Parses specified configuration
    ///
    /// Walks over specified logging configuration JSON structures and store
    /// parsed information in config_->logging_info_.
    ///
62
    /// @param log_config JSON structures to be parsed (loggers list)
Tomek Mrugalski's avatar
Tomek Mrugalski committed
63
    /// @param verbose specifies verbose mode (true forces DEBUG, debuglevel = 99)
64
    void parseConfiguration(const isc::data::ConstElementPtr& log_config,
Tomek Mrugalski's avatar
Tomek Mrugalski committed
65
                            bool verbose = false);
66
67
68
69
70

    /// @brief Applies stored configuration
    void applyConfiguration();

    /// @brief Configures default logging
Tomek Mrugalski's avatar
Tomek Mrugalski committed
71
72
73
74
75
    ///
    /// This method is static,
    ///
    /// @param verbose specifies verbose mode (true forces DEBUG, debuglevel = 99)
    void applyDefaultConfiguration(bool verbose = false);
76

Tomek Mrugalski's avatar
Tomek Mrugalski committed
77
private:
78
79
80
81
82
83
84
85
86

    /// @brief Parses one JSON structure in Logging/loggers" array
    ///
    /// @param entry JSON structure to be parsed
    /// @brief parses one structure in Logging/loggers.
    void parseConfigEntry(isc::data::ConstElementPtr entry);

    /// @brief Parses output_options structure
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
87
88
89
90
91
92
93
94
95
    /// An example data structure that holds output_options in JSON format
    /// looks like this:
    ///     "output_options": [
    ///         {
    ///             "output": "/var/log/kea-warn.log",
    ///             "maxver": 8,
    ///             "maxsize": 204800
    ///         }
    ///     ],
96
97
98
99
100
101
102
103
104
    /// @param destination parsed parameters will be stored here
    /// @param output_options element to be parsed
    void parseOutputOptions(std::vector<LoggingDestination>& destination,
                            isc::data::ConstElementPtr output_options);

    /// @brief Configuration is stored here
    ///
    /// LogConfigParser class uses only config_->logging_info_ field.
    ConfigurationPtr config_;
Tomek Mrugalski's avatar
Tomek Mrugalski committed
105
106
107
108
109
110

    /// @brief Verbose mode
    ///
    /// When verbose mode is enabled, logging severity is overridden to DEBUG,
    /// and debuglevel is always 99.
    bool verbose_;
111
112
113
114
115
};

} // namespace isc::dhcp
} // namespace isc

Tomek Mrugalski's avatar
Tomek Mrugalski committed
116
#endif // DHCPSRV_LOGGING_H