LCOV - code coverage report
Current view: top level - log - logger_manager_impl.h (source / functions) Hit Total Coverage
Test: report.info Lines: 0 2 0.0 %
Date: 2012-05-15 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 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_MANAGER_IMPL_H
      16                 :            : #define __LOGGER_MANAGER_IMPL_H
      17                 :            : 
      18                 :            : #include <string>
      19                 :            : 
      20                 :            : #include <log4cplus/appender.h>
      21                 :            : #include <log/logger_level.h>
      22                 :            : 
      23                 :            : // Forward declaration to avoid need to include log4cplus header file here.
      24                 :            : namespace log4cplus {
      25                 :            : class Logger;
      26                 :            : class Appender;
      27                 :            : }
      28                 :            : 
      29                 :            : namespace isc {
      30                 :            : namespace log {
      31                 :            : 
      32                 :            : // Forward declarations
      33                 :            : class LoggerSpecification;
      34                 :            : struct OutputOption;
      35                 :            : 
      36                 :            : /// \brief Logger Manager Implementation
      37                 :            : ///
      38                 :            : /// This is the implementation of the logger manager for the log4cplus
      39                 :            : /// underlying logger.
      40                 :            : ///
      41                 :            : /// As noted in logger_manager.h, the logger manager class exists to set up the
      42                 :            : /// logging given a set of specifications.  This class handles the processing
      43                 :            : /// of those specifications.
      44                 :            : ///
      45                 :            : /// Note: the logging has been implemented using a "pimpl" idiom to conceal
      46                 :            : /// the underlying implementation (log4cplus) from the BIND 10 interface.
      47                 :            : /// This requires that there be an implementation class, even though in this
      48                 :            : /// case, all the implementation class methods can be declared static.
      49                 :            : 
      50                 :            : class LoggerManagerImpl {
      51                 :            : public:
      52                 :            : 
      53                 :            :     /// \brief Constructor
      54                 :          0 :     LoggerManagerImpl()
      55                 :          0 :     {}
      56                 :            : 
      57                 :            :     /// \brief Initialize Processing
      58                 :            :     ///
      59                 :            :     /// This resets the hierachy of loggers back to their defaults.  This means
      60                 :            :     /// that all non-root loggers (if they exist) are set to NOT_SET, and the
      61                 :            :     /// root logger reset to logging informational messages.
      62                 :            :     static void processInit();
      63                 :            : 
      64                 :            :     /// \brief Process Specification
      65                 :            :     ///
      66                 :            :     /// Processes the specification for a single logger.
      67                 :            :     ///
      68                 :            :     /// \param spec Logging specification for this logger
      69                 :            :     static void processSpecification(const LoggerSpecification& spec);
      70                 :            : 
      71                 :            :     /// \brief End Processing
      72                 :            :     ///
      73                 :            :     /// Terminates the processing of the logging specifications.
      74                 :            :     static void processEnd()
      75                 :            :     {}
      76                 :            : 
      77                 :            :     /// \brief Implementation-specific initialization
      78                 :            :     ///
      79                 :            :     /// Sets the basic configuration for logging (the root logger has INFO and
      80                 :            :     /// more severe messages routed to stdout).  Unless this function (or
      81                 :            :     /// process() with a valid specification for all loggers that will log
      82                 :            :     /// messages) is called before a message is logged, log4cplus will output
      83                 :            :     /// a message to stderr noting that logging has not been initialized.
      84                 :            :     ///
      85                 :            :     /// It is assumed here that the name of the BIND 10 root logger can be
      86                 :            :     /// obtained from the global function getRootLoggerName().
      87                 :            :     ///
      88                 :            :     /// \param severity Severity to be associated with this logger
      89                 :            :     /// \param dbglevel Debug level associated with the root logger
      90                 :            :     static void init(isc::log::Severity severity = isc::log::INFO,
      91                 :            :                      int dbglevel = 0);
      92                 :            : 
      93                 :            :     /// \brief Reset logging
      94                 :            :     ///
      95                 :            :     /// Resets to default configuration (root logger logging to the console
      96                 :            :     /// with INFO severity).
      97                 :            :     ///
      98                 :            :     /// \param severity Severity to be associated with this logger
      99                 :            :     /// \param dbglevel Debug level associated with the root logger
     100                 :            :     static void reset(isc::log::Severity severity = isc::log::INFO,
     101                 :            :                       int dbglevel = 0);
     102                 :            : 
     103                 :            : private:
     104                 :            :     /// \brief Create console appender
     105                 :            :     ///
     106                 :            :     /// Creates an object that, when attached to a logger, will log to one
     107                 :            :     /// of the output streams (stdout or stderr).
     108                 :            :     ///
     109                 :            :     /// \param logger Log4cplus logger to which the appender must be attached.
     110                 :            :     /// \param opt Output options for this appender.
     111                 :            :     static void createConsoleAppender(log4cplus::Logger& logger,
     112                 :            :                                       const OutputOption& opt);
     113                 :            : 
     114                 :            :     /// \brief Create file appender
     115                 :            :     ///
     116                 :            :     /// Creates an object that, when attached to a logger, will log to a
     117                 :            :     /// specified file.  This also includes the ability to "roll" files when
     118                 :            :     /// they reach a specified size.
     119                 :            :     ///
     120                 :            :     /// \param logger Log4cplus logger to which the appender must be attached.
     121                 :            :     /// \param opt Output options for this appender.
     122                 :            :     static void createFileAppender(log4cplus::Logger& logger,
     123                 :            :                                    const OutputOption& opt);
     124                 :            : 
     125                 :            :     /// \brief Create syslog appender
     126                 :            :     ///
     127                 :            :     /// Creates an object that, when attached to a logger, will log to the
     128                 :            :     /// syslog file.
     129                 :            :     ///
     130                 :            :     /// \param logger Log4cplus logger to which the appender must be attached.
     131                 :            :     /// \param opt Output options for this appender.
     132                 :            :     static void createSyslogAppender(log4cplus::Logger& logger,
     133                 :            :                                      const OutputOption& opt);
     134                 :            : 
     135                 :            :     /// \brief Set default layout and severity for root logger
     136                 :            :     ///
     137                 :            :     /// Initializes the root logger to BIND 10 defaults - console output and
     138                 :            :     /// the passed severity/debug level.
     139                 :            :     ///
     140                 :            :     /// \param severity Severity of messages that the logger should output.
     141                 :            :     /// \param dbglevel Debug level if severity = DEBUG
     142                 :            :     static void initRootLogger(isc::log::Severity severity = isc::log::INFO,
     143                 :            :                                int dbglevel = 0);
     144                 :            : 
     145                 :            :     /// \brief Set layout for console appender
     146                 :            :     ///
     147                 :            :     /// Sets the layout of the specified appender to one suitable for file
     148                 :            :     /// or console output:
     149                 :            :     ///
     150                 :            :     /// YYYY-MM-DD HH:MM:SS.ssss SEVERITY [root.logger] message
     151                 :            :     ///
     152                 :            :     /// \param appender Appender for which this pattern is to be set.
     153                 :            :     static void setConsoleAppenderLayout(log4cplus::SharedAppenderPtr& appender);
     154                 :            : 
     155                 :            :     /// \brief Set layout for syslog appender
     156                 :            :     ///
     157                 :            :     /// Sets the layout of the specified appender to one suitable for the
     158                 :            :     /// syslog file:
     159                 :            :     ///
     160                 :            :     /// SEVERITY [root.logger] message
     161                 :            :     ///
     162                 :            :     /// \param appender Appender for which this pattern is to be set.
     163                 :            :     static void setSyslogAppenderLayout(log4cplus::SharedAppenderPtr& appender);
     164                 :            : };
     165                 :            : 
     166                 :            : } // namespace log
     167                 :            : } // namespace isc
     168                 :            : 
     169                 :            : #endif // __LOGGER_MANAGER_IMPL_H

Generated by: LCOV version 1.9