LCOV - code coverage report
Current view: top level - log - logger_manager.h (source / functions) Hit Total Coverage
Test: report.info Lines: 9 11 81.8 %
Date: 2012-05-15 Functions: 1 3 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 14 57.1 %

           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_MANAGER_H
      16                 :            : #define __LOGGER_MANAGER_H
      17                 :            : 
      18                 :            : #include "exceptions/exceptions.h"
      19                 :            : #include <log/logger_specification.h>
      20                 :            : 
      21                 :            : // Generated if, when updating the logging specification, an unknown
      22                 :            : // destination is encountered.
      23                 :          0 : class UnknownLoggingDestination : public isc::Exception {
      24                 :            : public:
      25                 :            :     UnknownLoggingDestination(const char* file, size_t line, const char* what) :
      26                 :          0 :         isc::Exception(file, line, what)
      27                 :            :     {}
      28                 :            : };
      29                 :            : 
      30                 :            : namespace isc {
      31                 :            : namespace log {
      32                 :            : 
      33                 :            : class LoggerManagerImpl;
      34                 :            : 
      35                 :            : /// \brief Logger Manager
      36                 :            : ///
      37                 :            : /// The logger manager class exists to process the set of logger specifications
      38                 :            : /// and use them to set up the logging in the program appropriately.
      39                 :            : ///
      40                 :            : /// To isolate the underlying implementation from basic processing, the
      41                 :            : /// LoggerManager is implemented using the "pimpl" idiom.
      42                 :            : 
      43                 :            : class LoggerManager {
      44                 :            : public:
      45                 :            :     /// \brief Constructor
      46                 :            :     LoggerManager();
      47                 :            : 
      48                 :            :     /// \brief Destructor
      49                 :            :     ~LoggerManager();
      50                 :            : 
      51                 :            :     /// \brief Process Specifications
      52                 :            :     ///
      53                 :            :     /// Replaces the current logging configuration by the one given.
      54                 :            :     ///
      55                 :            :     /// \param start Iterator pointing to the start of the collection of
      56                 :            :     ///        logging specifications.
      57                 :            :     /// \param finish Iterator pointing to the end of the collection of
      58                 :            :     ///        logging specification.
      59                 :            :     template <typename T>
      60                 :            :     void process(T start, T finish) {
      61         [ +  - ]:        151 :         processInit();
      62         [ +  + ]:        164 :         for (T i = start; i != finish; ++i) {
      63         [ +  - ]:         13 :             processSpecification(*i);
      64                 :            :         }
      65         [ +  - ]:        151 :         processEnd();
      66                 :            :     }
      67                 :            : 
      68                 :            :     /// \brief Process a single specification
      69                 :            :     ///
      70                 :            :     /// A convenience function for a single specification.
      71                 :            :     ///
      72                 :            :     /// \param spec Specification to process
      73                 :          3 :     void process(const LoggerSpecification& spec) {
      74         [ +  - ]:         49 :         processInit();
      75         [ +  - ]:         49 :         processSpecification(spec);
      76         [ +  - ]:         49 :         processEnd();
      77                 :          3 :     }
      78                 :            : 
      79                 :            :     /// \brief Run-Time Initialization
      80                 :            :     ///
      81                 :            :     /// Performs run-time initialization of the logger system, in particular
      82                 :            :     /// supplying the root logger name and name of a replacement message file.
      83                 :            :     ///
      84                 :            :     /// This must be the first logging function called in the program.  If
      85                 :            :     /// an attempt is made to log a message before this is function is called,
      86                 :            :     /// the results will be dependent on the underlying logging package.
      87                 :            :     ///
      88                 :            :     /// \param root Name of the root logger.  This should be set to the name of
      89                 :            :     ///        the program.
      90                 :            :     /// \param severity Severity at which to log
      91                 :            :     /// \param dbglevel Debug severity (ignored if "severity" is not "DEBUG")
      92                 :            :     /// \param file Name of the local message file.  This must be NULL if there
      93                 :            :     ///        is no local message file.
      94                 :            :     static void init(const std::string& root,
      95                 :            :                     isc::log::Severity severity = isc::log::INFO,
      96                 :            :                     int dbglevel = 0, const char* file = NULL);
      97                 :            : 
      98                 :            :     /// \brief Reset logging
      99                 :            :     ///
     100                 :            :     /// Resets logging to whatever was set in the call to init().
     101                 :            :     static void reset();
     102                 :            : 
     103                 :            :     /// \brief Read local message file
     104                 :            :     ///
     105                 :            :     /// Reads the local message file into the global dictionary, overwriting
     106                 :            :     /// existing messages.  If the file contained any message IDs not in the
     107                 :            :     /// dictionary, they are listed in a warning message.
     108                 :            :     ///
     109                 :            :     /// \param file Name of the local message file
     110                 :            :     static void readLocalMessageFile(const char* file);
     111                 :            : 
     112                 :            : private:
     113                 :            :     /// \brief Initialize Processing
     114                 :            :     ///
     115                 :            :     /// Initializes the processing of a list of specifications by resetting all
     116                 :            :     /// loggers to their defaults, which is to pass the message to their
     117                 :            :     /// parent logger.  (Except for the root logger, where the default action is
     118                 :            :     /// to output the message.)
     119                 :            :     void processInit();
     120                 :            : 
     121                 :            :     /// \brief Process Logging Specification
     122                 :            :     ///
     123                 :            :     /// Processes the given specification.  It is assumed at this point that
     124                 :            :     /// either the logger does not exist or has been made inactive.
     125                 :            :     void processSpecification(const LoggerSpecification& spec);
     126                 :            : 
     127                 :            :     /// \brief End Processing
     128                 :            :     ///
     129                 :            :     /// Place holder for finish processing.
     130                 :            :     /// TODO: Check that the root logger has something enabled
     131                 :            :     void processEnd();
     132                 :            : 
     133                 :            :     // Members
     134                 :            :     LoggerManagerImpl*  impl_;      ///< Pointer to implementation
     135                 :            : };
     136                 :            : 
     137                 :            : } // namespace log
     138                 :            : } // namespace isc
     139                 :            : 
     140                 :            : 
     141                 :            : #endif // __LOGGER_MANAGER_H

Generated by: LCOV version 1.9