LCOV - code coverage report
Current view: top level - log - logger_specification.h (source / functions) Hit Total Coverage
Test: report.info Lines: 17 29 58.6 %
Date: 2012-05-15 Functions: 3 10 30.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 18 50.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #ifndef __LOGGER_SPECIFICATION_H
      16                 :            : #define __LOGGER_SPECIFICATION_H
      17                 :            : 
      18                 :            : #include <stdint.h>
      19                 :            : #include <stdlib.h>
      20                 :            : 
      21                 :            : #include <log/logger_level.h>
      22                 :            : #include <log/output_option.h>
      23                 :            : 
      24                 :            : /// \brief Logger Specification
      25                 :            : ///
      26                 :            : /// The logging configuration options are a list of logger specifications, each
      27                 :            : /// of which represents a logger and the options for its appenders.
      28                 :            : ///
      29                 :            : /// Unlike OutputOption (which is a struct), this contains a bit more
      30                 :            : /// structure and is concealed in a class.
      31                 :            : 
      32                 :            : #include <vector>
      33                 :            : 
      34                 :            : namespace isc {
      35                 :            : namespace log {
      36                 :            : 
      37         [ +  - ]:        104 : class LoggerSpecification {
      38                 :            : public:
      39                 :            :     typedef std::vector<OutputOption>::iterator         iterator;
      40                 :            :     typedef std::vector<OutputOption>::const_iterator   const_iterator;
      41                 :            : 
      42                 :            :     /// \brief Constructor
      43                 :            :     ///
      44                 :            :     /// \param name Name of the logger.
      45                 :            :     /// \param severity Severity at which this logger logs
      46                 :            :     /// \param dbglevel Debug level
      47                 :            :     /// \param additive true to cause message logged with this logger to be
      48                 :            :     ///        passed to the parent for logging.
      49                 :            :     LoggerSpecification(const std::string& name = "",
      50                 :            :                         isc::log::Severity severity = isc::log::INFO,
      51                 :            :                         int dbglevel = 0, bool additive = false) :
      52                 :            :         name_(name), severity_(severity), dbglevel_(dbglevel),
      53   [ +  -  +  -  :         63 :         additive_(additive)
             +  -  +  - ]
                 [ +  - ]
      54                 :            :     {}
      55                 :            : 
      56                 :            :     /// \brief Set the name of the logger.
      57                 :            :     ///
      58                 :            :     /// \param name Name of the logger.
      59                 :            :     void setName(const std::string& name) {
      60                 :          5 :         name_ = name;
      61                 :            :     }
      62                 :            : 
      63                 :            :     /// \return Return logger name.
      64                 :            :     std::string getName() const {
      65   [ +  -  +  -  :         65 :         return name_;
                   +  - ]
      66                 :            :     }
      67                 :            : 
      68                 :            :     /// \brief Set the severity.
      69                 :            :     ///
      70                 :            :     /// \param severity New severity of the logger.
      71                 :          0 :     void setSeverity(isc::log::Severity severity) {
      72                 :         12 :         severity_ = severity;
      73                 :          0 :     }
      74                 :            : 
      75                 :            :     /// \return Return logger severity.
      76                 :          0 :     isc::log::Severity getSeverity() const {
      77                 :          0 :         return severity_;
      78                 :            :     }
      79                 :            : 
      80                 :            :     /// \brief Set the debug level.
      81                 :            :     ///
      82                 :            :     /// \param dbglevel New debug level of the logger.
      83                 :          0 :     void setDbglevel(int dbglevel) {
      84                 :          2 :         dbglevel_ = dbglevel;
      85                 :          0 :     }
      86                 :            : 
      87                 :            :     /// \return Return logger debug level
      88                 :          0 :     int getDbglevel() const {
      89                 :          0 :         return dbglevel_;
      90                 :            :     }
      91                 :            : 
      92                 :            :     /// \brief Set the additive flag.
      93                 :            :     ///
      94                 :            :     /// \param additive New value of the additive flag.
      95                 :          0 :     void setAdditive(bool additive) {
      96                 :          1 :         additive_ = additive;
      97                 :          0 :     }
      98                 :            : 
      99                 :            :     /// \return Return additive flag.
     100                 :          0 :     bool getAdditive() const {
     101                 :          0 :         return additive_;
     102                 :            :     }
     103                 :            : 
     104                 :            :     /// \brief Add output option.
     105                 :            :     ///
     106                 :            :     /// \param option Option to add to the list.
     107                 :         15 :     void addOutputOption(const OutputOption& option) {
     108                 :         63 :         options_.push_back(option);
     109                 :         15 :     }
     110                 :            : 
     111                 :            :     /// \return Iterator to start of output options.
     112                 :            :     iterator begin() {
     113                 :          2 :         return options_.begin();
     114                 :            :     }
     115                 :            : 
     116                 :            :     /// \return Iterator to start of output options.
     117                 :            :     const_iterator begin() const {
     118                 :            :         return options_.begin();
     119                 :            :     }
     120                 :            : 
     121                 :            :     /// \return Iterator to end of output options.
     122                 :            :     iterator end() {
     123                 :          2 :         return options_.end();
     124                 :            :     }
     125                 :            : 
     126                 :            :     /// \return Iterator to end of output options.
     127                 :            :     const_iterator end() const {
     128                 :            :         return options_.end();
     129                 :            :     }
     130                 :            : 
     131                 :            :     /// \return Number of output specification options.
     132                 :            :     size_t optionCount() const {
     133                 :            :         return options_.size();
     134                 :            :     }
     135                 :            : 
     136                 :            :     /// \brief Reset back to defaults.
     137                 :            :     void reset() {
     138                 :          1 :         name_ = "";
     139                 :          1 :         severity_ = isc::log::INFO;
     140                 :          1 :         dbglevel_ = 0;
     141                 :          1 :         additive_ = false;
     142                 :          1 :         options_.clear();
     143                 :            :     }
     144                 :            : 
     145                 :            : private:
     146                 :            :     std::string                 name_;          ///< Logger name
     147                 :            :     isc::log::Severity          severity_;      ///< Severity for this logger
     148                 :            :     int                         dbglevel_;      ///< Debug level
     149                 :            :     bool                        additive_;      ///< Chaining output 
     150                 :            :     std::vector<OutputOption>   options_;       ///< Logger options
     151                 :            : };
     152                 :            : 
     153                 :            : } // namespace log
     154                 :            : } // namespace isc
     155                 :            : 
     156                 :            : #endif // __LOGGER_SPEC_IFICATIONH

Generated by: LCOV version 1.9