LCOV - code coverage report
Current view: top level - log - logger_impl.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 32 32 100.0 %
Date: 2012-05-15 Functions: 11 11 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 46 54.3 %

           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                 :            : #include <iostream>
      16                 :            : #include <iomanip>
      17                 :            : #include <algorithm>
      18                 :            : 
      19                 :            : #include <stdarg.h>
      20                 :            : #include <stdio.h>
      21                 :            : #include <boost/lexical_cast.hpp>
      22                 :            : #include <boost/static_assert.hpp>
      23                 :            : 
      24                 :            : #include <log4cplus/configurator.h>
      25                 :            : 
      26                 :            : #include <log/logger.h>
      27                 :            : #include <log/logger_impl.h>
      28                 :            : #include <log/logger_level.h>
      29                 :            : #include <log/logger_level_impl.h>
      30                 :            : #include <log/logger_name.h>
      31                 :            : #include <log/message_dictionary.h>
      32                 :            : #include <log/message_types.h>
      33                 :            : 
      34                 :            : #include <util/strutil.h>
      35                 :            : 
      36                 :            : // Note: as log4cplus and the BIND 10 logger have many concepts in common, and
      37                 :            : // thus many similar names, to disambiguate types we don't "use" the log4cplus
      38                 :            : // namespace: instead, all log4cplus types are explicitly qualified.
      39                 :            : 
      40                 :            : using namespace std;
      41                 :            : 
      42                 :            : namespace isc {
      43                 :            : namespace log {
      44                 :            : 
      45                 :            : // Constructor.  The setting of logger_ must be done when the variable is
      46                 :            : // constructed (instead of being left to the body of the function); at least
      47                 :            : // one compiler requires that all member variables be constructed before the
      48                 :            : // constructor is run, but log4cplus::Logger (the type of logger_) has no
      49                 :            : // default constructor.
      50                 :        169 : LoggerImpl::LoggerImpl(const string& name) : name_(expandLoggerName(name)),
      51         [ +  - ]:        169 :     logger_(log4cplus::Logger::getInstance(name_))
      52                 :            : {
      53                 :        169 : }
      54                 :            : 
      55                 :            : // Destructor. (Here because of virtual declaration.)
      56                 :            : 
      57         [ +  - ]:        167 : LoggerImpl::~LoggerImpl() {
      58                 :        334 : }
      59                 :            : 
      60                 :            : // Set the severity for logging.
      61                 :            : void
      62                 :         53 : LoggerImpl::setSeverity(isc::log::Severity severity, int dbglevel) {
      63                 :            :     Level level(severity, dbglevel);
      64                 :         53 :     logger_.setLogLevel(LoggerLevelImpl::convertFromBindLevel(level));
      65                 :         53 : }
      66                 :            : 
      67                 :            : // Return severity level
      68                 :            : isc::log::Severity
      69                 :         18 : LoggerImpl::getSeverity() {
      70                 :         18 :     Level level = LoggerLevelImpl::convertToBindLevel(logger_.getLogLevel());
      71                 :         18 :     return level.severity;
      72                 :            : }
      73                 :            : 
      74                 :            : // Return current debug level (only valid if current severity level is DEBUG).
      75                 :            : int
      76                 :         14 : LoggerImpl::getDebugLevel() {
      77                 :         14 :     Level level = LoggerLevelImpl::convertToBindLevel(logger_.getLogLevel());
      78                 :         14 :     return level.dbglevel;
      79                 :            : }
      80                 :            : 
      81                 :            : // Get effective severity.  Either the current severity or, if not set, the
      82                 :            : // severity of the root level.
      83                 :            : isc::log::Severity
      84                 :         15 : LoggerImpl::getEffectiveSeverity() {
      85                 :         15 :     Level level = LoggerLevelImpl::convertToBindLevel(logger_.getChainedLogLevel());
      86                 :         15 :     return level.severity;
      87                 :            : }
      88                 :            : 
      89                 :            : // Return effective debug level (only valid if current effective severity level
      90                 :            : // is DEBUG).
      91                 :            : int
      92                 :         10 : LoggerImpl::getEffectiveDebugLevel() {
      93                 :         10 :     Level level = LoggerLevelImpl::convertToBindLevel(logger_.getChainedLogLevel());
      94                 :         10 :     return level.dbglevel;
      95                 :            : }
      96                 :            : 
      97                 :            : 
      98                 :            : // Output a general message
      99                 :            : string*
     100                 :      40793 : LoggerImpl::lookupMessage(const MessageID& ident) {
     101                 :      40793 :     return (new string(string(ident) + " " +
     102 [ +  - ][ +  - ]:     122379 :                        MessageDictionary::globalDictionary().getText(ident)));
                 [ +  - ]
     103                 :            : }
     104                 :            : 
     105                 :            : void
     106                 :      40793 : LoggerImpl::outputRaw(const Severity& severity, const string& message) {
     107   [ +  +  +  +  :      40793 :     switch (severity) {
                   +  - ]
     108                 :            :         case DEBUG:
     109 [ +  - ][ +  - ]:      78886 :             LOG4CPLUS_DEBUG(logger_, message);
                 [ +  - ]
     110                 :            :             break;
     111                 :            : 
     112                 :            :         case INFO:
     113 [ +  - ][ +  - ]:       1640 :             LOG4CPLUS_INFO(logger_, message);
                 [ +  - ]
     114                 :            :             break;
     115                 :            : 
     116                 :            :         case WARN:
     117 [ +  - ][ +  - ]:        278 :             LOG4CPLUS_WARN(logger_, message);
                 [ +  - ]
     118                 :            :             break;
     119                 :            : 
     120                 :            :         case ERROR:
     121 [ +  - ][ +  - ]:        678 :             LOG4CPLUS_ERROR(logger_, message);
                 [ +  - ]
     122                 :            :             break;
     123                 :            : 
     124                 :            :         case FATAL:
     125 [ +  - ][ +  - ]:        104 :             LOG4CPLUS_FATAL(logger_, message);
                 [ +  - ]
     126                 :            :     }
     127                 :      40793 : }
     128                 :            : 
     129                 :            : } // namespace log
     130                 :        141 : } // namespace isc

Generated by: LCOV version 1.9