LCOV - code coverage report
Current view: top level - log - logger.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 52 52 100.0 %
Date: 2012-05-15 Functions: 22 22 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 20 70.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                 :            : #include <stdarg.h>
      16                 :            : #include <stdio.h>
      17                 :            : 
      18                 :            : #include <log/logger.h>
      19                 :            : #include <log/logger_impl.h>
      20                 :            : #include <log/logger_name.h>
      21                 :            : #include <log/logger_support.h>
      22                 :            : #include <log/message_dictionary.h>
      23                 :            : #include <log/message_types.h>
      24                 :            : 
      25                 :            : #include <util/strutil.h>
      26                 :            : 
      27                 :            : using namespace std;
      28                 :            : 
      29                 :            : namespace isc {
      30                 :            : namespace log {
      31                 :            : 
      32                 :            : // Initialize underlying logger, but only if logging has been initialized.
      33                 :        171 : void Logger::initLoggerImpl() {
      34         [ +  + ]:        171 :     if (isLoggingInitialized()) {
      35 [ +  - ][ +  - ]:        169 :         loggerptr_ = new LoggerImpl(name_);
      36                 :            :     } else {
      37         [ +  - ]:          4 :         isc_throw(LoggingNotInitialized, "attempt to access logging function "
      38                 :            :                   "before logging has been initialized");
      39                 :            :     }
      40                 :        169 : }
      41                 :            : 
      42                 :            : // Destructor.
      43                 :            : 
      44                 :        976 : Logger::~Logger() {
      45         [ +  + ]:        783 :     delete loggerptr_;
      46                 :        976 : }
      47                 :            : 
      48                 :            : // Get Name of Logger
      49                 :            : 
      50                 :            : std::string
      51                 :          4 : Logger::getName() {
      52                 :          4 :     return (getLoggerPtr()->getName());
      53                 :            : }
      54                 :            : 
      55                 :            : // Set the severity for logging.
      56                 :            : 
      57                 :            : void
      58                 :         53 : Logger::setSeverity(isc::log::Severity severity, int dbglevel) {
      59                 :         53 :     getLoggerPtr()->setSeverity(severity, dbglevel);
      60                 :         53 : }
      61                 :            : 
      62                 :            : // Return the severity of the logger.
      63                 :            : 
      64                 :            : isc::log::Severity
      65                 :         18 : Logger::getSeverity() {
      66                 :         18 :     return (getLoggerPtr()->getSeverity());
      67                 :            : }
      68                 :            : 
      69                 :            : // Get Effective Severity Level for Logger
      70                 :            : 
      71                 :            : isc::log::Severity
      72                 :         15 : Logger::getEffectiveSeverity() {
      73                 :         15 :     return (getLoggerPtr()->getEffectiveSeverity());
      74                 :            : }
      75                 :            : 
      76                 :            : // Debug level (only relevant if messages of severity DEBUG are being logged).
      77                 :            : 
      78                 :            : int
      79                 :         14 : Logger::getDebugLevel() {
      80                 :         14 :     return (getLoggerPtr()->getDebugLevel());
      81                 :            : }
      82                 :            : 
      83                 :            : // Effective debug level (only relevant if messages of severity DEBUG are being
      84                 :            : // logged).
      85                 :            : 
      86                 :            : int
      87                 :         10 : Logger::getEffectiveDebugLevel() {
      88                 :         10 :     return (getLoggerPtr()->getEffectiveDebugLevel());
      89                 :            : }
      90                 :            : 
      91                 :            : // Check on the current severity settings
      92                 :            : 
      93                 :            : bool
      94                 :      78680 : Logger::isDebugEnabled(int dbglevel) {
      95                 :      78680 :     return (getLoggerPtr()->isDebugEnabled(dbglevel));
      96                 :            : }
      97                 :            : 
      98                 :            : bool
      99                 :        921 : Logger::isInfoEnabled() {
     100                 :        921 :     return (getLoggerPtr()->isInfoEnabled());
     101                 :            : }
     102                 :            : 
     103                 :            : bool
     104                 :        214 : Logger::isWarnEnabled() {
     105                 :        214 :     return (getLoggerPtr()->isWarnEnabled());
     106                 :            : }
     107                 :            : 
     108                 :            : bool
     109                 :        534 : Logger::isErrorEnabled() {
     110                 :        534 :     return (getLoggerPtr()->isErrorEnabled());
     111                 :            : }
     112                 :            : 
     113                 :            : bool
     114                 :        105 : Logger::isFatalEnabled() {
     115                 :        105 :     return (getLoggerPtr()->isFatalEnabled());
     116                 :            : }
     117                 :            : 
     118                 :            : // Format a message: looks up the message text in the dictionary and formats
     119                 :            : // it, replacing tokens with arguments.
     120                 :            : //
     121                 :            : // Owing to the use of variable arguments, this must be inline (hence the
     122                 :            : // definition of the macro).  Also note that it expects that the message buffer
     123                 :            : // "message" is declared in the compilation unit.
     124                 :            : 
     125                 :            : // Output methods
     126                 :            : 
     127                 :            : void
     128                 :      40793 : Logger::output(const Severity& severity, const std::string& message) {
     129                 :      40793 :     getLoggerPtr()->outputRaw(severity, message);
     130                 :      40793 : }
     131                 :            : 
     132                 :            : Logger::Formatter
     133                 :      39863 : Logger::debug(int dbglevel, const isc::log::MessageID& ident) {
     134         [ +  + ]:      39863 :     if (isDebugEnabled(dbglevel)) {
     135                 :            :         return (Formatter(DEBUG, getLoggerPtr()->lookupMessage(ident),
     136                 :      39443 :                           this));
     137                 :            :     } else {
     138                 :            :         return (Formatter());
     139                 :            :     }
     140                 :            : }
     141                 :            : 
     142                 :            : Logger::Formatter
     143                 :        849 : Logger::info(const isc::log::MessageID& ident) {
     144         [ +  + ]:        849 :     if (isInfoEnabled()) {
     145                 :            :         return (Formatter(INFO, getLoggerPtr()->lookupMessage(ident),
     146                 :        820 :                           this));
     147                 :            :     } else {
     148                 :            :         return (Formatter());
     149                 :            :     }
     150                 :            : }
     151                 :            : 
     152                 :            : Logger::Formatter
     153                 :        139 : Logger::warn(const isc::log::MessageID& ident) {
     154         [ +  - ]:        139 :     if (isWarnEnabled()) {
     155                 :            :         return (Formatter(WARN, getLoggerPtr()->lookupMessage(ident),
     156                 :        139 :                           this));
     157                 :            :     } else {
     158                 :            :         return (Formatter());
     159                 :            :     }
     160                 :            : }
     161                 :            : 
     162                 :            : Logger::Formatter
     163                 :        339 : Logger::error(const isc::log::MessageID& ident) {
     164         [ +  - ]:        339 :     if (isErrorEnabled()) {
     165                 :            :         return (Formatter(ERROR, getLoggerPtr()->lookupMessage(ident),
     166                 :        339 :                           this));
     167                 :            :     } else {
     168                 :            :         return (Formatter());
     169                 :            :     }
     170                 :            : }
     171                 :            : 
     172                 :            : Logger::Formatter
     173                 :         52 : Logger::fatal(const isc::log::MessageID& ident) {
     174         [ +  - ]:         52 :     if (isFatalEnabled()) {
     175                 :            :         return (Formatter(FATAL, getLoggerPtr()->lookupMessage(ident),
     176                 :         52 :                           this));
     177                 :            :     } else {
     178                 :            :         return (Formatter());
     179                 :            :     }
     180                 :            : }
     181                 :            : 
     182                 :            : // Comparison (testing only)
     183                 :            : 
     184                 :            : bool
     185                 :          2 : Logger::operator==(Logger& other) {
     186                 :          4 :     return (*getLoggerPtr() == *other.getLoggerPtr());
     187                 :            : }
     188                 :            : 
     189                 :            : } // namespace log
     190                 :        141 : } // namespace isc

Generated by: LCOV version 1.9