Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
Arc::Logger Class Reference

A logger class. More...

#include <Logger.h>

Collaboration diagram for Arc::Logger:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Logger (Logger &parent, const std::string &subdomain)
 Creates a logger.
 Logger (Logger &parent, const std::string &subdomain, LogLevel threshold)
 Creates a logger.
 ~Logger ()
 Destroys a logger.
void addDestination (LogDestination &destination)
 Adds a LogDestination.
void removeDestinations (void)
 Removes all LogDestinations.
void setThreshold (LogLevel threshold)
 Sets the threshold.
LogLevel getThreshold () const
 Returns the threshold.
void msg (LogMessage message)
 Sends a LogMessage.
void msg (LogLevel level, const std::string &str)
 Logs a message text.
template<class T0 >
void msg (LogLevel level, const std::string &str, const T0 &t0)
template<class T0 , class T1 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1)
template<class T0 , class T1 , class T2 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2)
template<class T0 , class T1 , class T2 , class T3 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2, const T3 &t3)
template<class T0 , class T1 , class T2 , class T3 , class T4 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4)
template<class T0 , class T1 , class T2 , class T3 , class T4 , class T5 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, const T5 &t5)
template<class T0 , class T1 , class T2 , class T3 , class T4 , class T5 , class T6 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, const T5 &t5, const T6 &t6)
template<class T0 , class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, const T5 &t5, const T6 &t6, const T7 &t7)

Static Public Member Functions

static LoggergetRootLogger ()
 The root Logger.

Private Member Functions

 Logger ()
 A private constructor.
 Logger (const Logger &unique)
 Private copy constructor.
void operator= (const Logger &unique)
 Private assignment operator.
std::string getDomain ()
 Returns the domain.
void log (const LogMessage &message)
 Forwards a log message.

Private Attributes

Loggerparent
 A pointer to the parent of this logger.
std::string domain
 The domain of this logger.
std::list< LogDestination * > destinations
 A list of pointers to LogDestinations.
LogLevel threshold
 The threshold of this Logger.

Static Private Attributes

static LoggerrootLogger = NULL
static unsigned int rootLoggerMark = ~rootLoggerMagic

Detailed Description

A logger class.

This class defines a Logger to which LogMessages can be sent.

Every Logger (except for the rootLogger) has a parent Logger. The
domain of a Logger (a string that indicates the origin of
LogMessages) is composed by adding a subdomain to the domain of
its parent Logger.

A Logger also has a threshold. Every LogMessage that have a level
that is greater than or equal to the threshold is forwarded to any
LogDestination connected to this Logger as well as to the parent
Logger.

Typical usage of the Logger class is to declare a global Logger
object for each library/module/component to be used by all classes
and methods there.

Definition at line 383 of file Logger.h.


Constructor & Destructor Documentation

Arc::Logger::Logger ( Logger parent,
const std::string &  subdomain 
)

Creates a logger.

Creates a logger. The threshold is inherited from its parent Logger.

Parameters:
parentThe parent Logger of the new Logger.
subdomainThe subdomain of the new logger.

Definition at line 351 of file Logger.cpp.

    : parent(&parent),
      domain(parent.getDomain() + "." + subdomain),
      threshold(parent.getThreshold()) {
    // Nothing else needs to be done.
  }
Arc::Logger::Logger ( Logger parent,
const std::string &  subdomain,
LogLevel  threshold 
)

Creates a logger.

Creates a logger.

Parameters:
parentThe parent Logger of the new Logger.
subdomainThe subdomain of the new logger.
thresholdThe threshold of the new logger.

Definition at line 359 of file Logger.cpp.

    : parent(&parent),
      domain(parent.getDomain() + "." + subdomain),
      threshold(threshold) {
    // Nothing else needs to be done.
  }

Destroys a logger.

Destructor

Definition at line 368 of file Logger.cpp.

                  {
  }
Arc::Logger::Logger ( ) [private]

A private constructor.

Every Logger (except the root logger) must have a parent, therefore the default constructor (which does not specify a parent) is private to prevent accidental use. It is only used when creating the root logger.

Definition at line 392 of file Logger.cpp.

    : parent(0),
      domain("Arc"),
      threshold(DEBUG) {
    // addDestination(cerr);
  }

Here is the caller graph for this function:

Arc::Logger::Logger ( const Logger unique) [private]

Private copy constructor.

Loggers should never be copied, therefore the copy constructor is private.

Definition at line 399 of file Logger.cpp.

                              {
    // Executing this code should be impossible!
    exit(EXIT_FAILURE);
  }

Member Function Documentation

Adds a LogDestination.

Adds a LogDestination to which to forward LogMessages sent to this logger (if they pass the threshold). Since LogDestinatoins should not be copied, the new LogDestination is passed by reference and a pointer to it is kept for later use. It is therefore important that the LogDestination passed to this Logger exists at least as long as the Logger iteslf.

Definition at line 371 of file Logger.cpp.

                                                         {
    destinations.push_back(&destination);
  }

Here is the caller graph for this function:

std::string Arc::Logger::getDomain ( ) [private]

Returns the domain.

This method returns the domain of this logger, i.e. the string that is attached to all LogMessages sent from this logger to indicate their origin.

Definition at line 409 of file Logger.cpp.

                              {
    return domain;
  }
Logger & Arc::Logger::getRootLogger ( void  ) [static]

The root Logger.

This is the root Logger. It is an ancestor of any other Logger and allways exists.

Definition at line 341 of file Logger.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the threshold.

Returns the threshold.

Returns:
The threshold of this Logger.

Definition at line 383 of file Logger.cpp.

                                      {
    return threshold;
  }

Here is the caller graph for this function:

void Arc::Logger::log ( const LogMessage message) [private]

Forwards a log message.

This method is called by the msg() method and by child Loggers. It filters messages based on their level and forwards them to the parent Logger and any LogDestination that has been added to this Logger.

Parameters:
messageThe message to send.

Definition at line 413 of file Logger.cpp.

                                            {
    if (message.getLevel() >= threshold) {
      std::list<LogDestination*>::iterator dest;
      std::list<LogDestination*>::iterator begin = destinations.begin();
      std::list<LogDestination*>::iterator end = destinations.end();
      for (dest = begin; dest != end; ++dest)
        (*dest)->log(message);
      if (parent != 0)
        parent->log(message);
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::Logger::msg ( LogMessage  message)

Sends a LogMessage.

Sends a LogMessage.

Parameters:
TheLogMessage to send.

Definition at line 387 of file Logger.cpp.

                                     {
    message.setDomain(domain);
    log(message);
  }

Here is the call graph for this function:

void Arc::Logger::msg ( LogLevel  level,
const std::string &  str 
) [inline]

Logs a message text.

Logs a message text string at the specified LogLevel. This is a convenience method to save some typing. It simply creates a LogMessage and sends it to the other msg() method.

Parameters:
levelThe level of the message.
strThe message text.

Definition at line 457 of file Logger.h.

                                                   {
      msg(LogMessage(level, IString(str)));
    }

Here is the call graph for this function:

template<class T0 >
void Arc::Logger::msg ( LogLevel  level,
const std::string &  str,
const T0 &  t0 
) [inline]

Definition at line 462 of file Logger.h.

                           {
      msg(LogMessage(level, IString(str, t0)));
    }

Here is the call graph for this function:

template<class T0 , class T1 >
void Arc::Logger::msg ( LogLevel  level,
const std::string &  str,
const T0 &  t0,
const T1 &  t1 
) [inline]

Definition at line 468 of file Logger.h.

                                         {
      msg(LogMessage(level, IString(str, t0, t1)));
    }

Here is the call graph for this function:

template<class T0 , class T1 , class T2 >
void Arc::Logger::msg ( LogLevel  level,
const std::string &  str,
const T0 &  t0,
const T1 &  t1,
const T2 &  t2 
) [inline]

Definition at line 474 of file Logger.h.

                                                       {
      msg(LogMessage(level, IString(str, t0, t1, t2)));
    }

Here is the call graph for this function:

template<class T0 , class T1 , class T2 , class T3 >
void Arc::Logger::msg ( LogLevel  level,
const std::string &  str,
const T0 &  t0,
const T1 &  t1,
const T2 &  t2,
const T3 &  t3 
) [inline]

Definition at line 480 of file Logger.h.

                                                                     {
      msg(LogMessage(level, IString(str, t0, t1, t2, t3)));
    }

Here is the call graph for this function:

template<class T0 , class T1 , class T2 , class T3 , class T4 >
void Arc::Logger::msg ( LogLevel  level,
const std::string &  str,
const T0 &  t0,
const T1 &  t1,
const T2 &  t2,
const T3 &  t3,
const T4 &  t4 
) [inline]

Definition at line 486 of file Logger.h.

                           {
      msg(LogMessage(level, IString(str, t0, t1, t2, t3, t4)));
    }

Here is the call graph for this function:

template<class T0 , class T1 , class T2 , class T3 , class T4 , class T5 >
void Arc::Logger::msg ( LogLevel  level,
const std::string &  str,
const T0 &  t0,
const T1 &  t1,
const T2 &  t2,
const T3 &  t3,
const T4 &  t4,
const T5 &  t5 
) [inline]

Definition at line 494 of file Logger.h.

                                         {
      msg(LogMessage(level, IString(str, t0, t1, t2, t3, t4, t5)));
    }

Here is the call graph for this function:

template<class T0 , class T1 , class T2 , class T3 , class T4 , class T5 , class T6 >
void Arc::Logger::msg ( LogLevel  level,
const std::string &  str,
const T0 &  t0,
const T1 &  t1,
const T2 &  t2,
const T3 &  t3,
const T4 &  t4,
const T5 &  t5,
const T6 &  t6 
) [inline]

Definition at line 502 of file Logger.h.

                                                       {
      msg(LogMessage(level, IString(str, t0, t1, t2, t3, t4, t5, t6)));
    }

Here is the call graph for this function:

template<class T0 , class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 >
void Arc::Logger::msg ( LogLevel  level,
const std::string &  str,
const T0 &  t0,
const T1 &  t1,
const T2 &  t2,
const T3 &  t3,
const T4 &  t4,
const T5 &  t5,
const T6 &  t6,
const T7 &  t7 
) [inline]

Definition at line 510 of file Logger.h.

                                                                     {
      msg(LogMessage(level, IString(str, t0, t1, t2, t3, t4, t5, t6, t7)));
    }

Here is the call graph for this function:

void Arc::Logger::operator= ( const Logger unique) [private]

Private assignment operator.

Loggers should never be assigned, therefore the assignment operator is private.

Definition at line 404 of file Logger.cpp.

                                      {
    // Executing this code should be impossible!
    exit(EXIT_FAILURE);
  }

Removes all LogDestinations.

Definition at line 375 of file Logger.cpp.

                                      {
    destinations.clear();
  }

Here is the caller graph for this function:

void Arc::Logger::setThreshold ( LogLevel  threshold)

Sets the threshold.

This method sets the threshold of the Logger. Any message sent to this Logger that has a level below this threshold will be discarded.

Parameters:
Thethreshold

Definition at line 379 of file Logger.cpp.

                                              {
    this->threshold = threshold;
  }

Here is the caller graph for this function:


Member Data Documentation

A list of pointers to LogDestinations.

Definition at line 561 of file Logger.h.

std::string Arc::Logger::domain [private]

The domain of this logger.

Definition at line 558 of file Logger.h.

A pointer to the parent of this logger.

Definition at line 555 of file Logger.h.

Logger * Arc::Logger::rootLogger = NULL [static, private]

Definition at line 567 of file Logger.h.

unsigned int Arc::Logger::rootLoggerMark = ~rootLoggerMagic [static, private]

Definition at line 568 of file Logger.h.

The threshold of this Logger.

Definition at line 564 of file Logger.h.


The documentation for this class was generated from the following files: