Back to index

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

A class for logging to ostreams. More...

#include <Logger.h>

Inheritance diagram for Arc::LogStream:
Inheritance graph
[legend]
Collaboration diagram for Arc::LogStream:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LogStream (std::ostream &destination)
 Creates a LogStream connected to an ostream.
 LogStream (std::ostream &destination, const std::string &locale)
 Creates a LogStream connected to an ostream.
virtual void log (const LogMessage &message)
 Writes a LogMessage to the stream.
void setFormat (const LogFormat &newformat)

Protected Attributes

std::string locale
LogFormat format

Private Member Functions

 LogStream (const LogStream &unique)
 Private copy constructor.
void operator= (const LogStream &unique)
 Private assignment operator.

Private Attributes

std::ostream & destination
 The ostream to which to write LogMessages.
Glib::Mutex mutex
 A mutex for synchronization.

Detailed Description

A class for logging to ostreams.

This class is used for logging to ostreams (cout, cerr, files). It provides synchronization in order to prevent different LogMessages to appear mixed with each other in the stream. In order not to break the synchronization, LogStreams should never be copied. Therefore the copy constructor and assignment operator are private. Furthermore, it is important to keep a LogStream object as long as the Logger to which it has been registered.

Definition at line 236 of file Logger.h.


Constructor & Destructor Documentation

Arc::LogStream::LogStream ( std::ostream &  destination)

Creates a LogStream connected to an ostream.

Creates a LogStream connected to the specified ostream. In order not to break synchronization, it is important not to connect more than one LogStream object to a certain stream.

Parameters:
destinationThe ostream to which to erite LogMessages.

Definition at line 201 of file Logger.cpp.

Arc::LogStream::LogStream ( std::ostream &  destination,
const std::string &  locale 
)

Creates a LogStream connected to an ostream.

Creates a LogStream connected to the specified ostream. The output will be localised to the specified locale.

Definition at line 204 of file Logger.cpp.

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

Private copy constructor.

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

Definition at line 220 of file Logger.cpp.

    : LogDestination(),
      destination(std::cerr) {
    // Executing this code should be impossible!
    exit(EXIT_FAILURE);
  }

Member Function Documentation

void Arc::LogStream::log ( const LogMessage message) [virtual]

Writes a LogMessage to the stream.

This method writes a LogMessage to the ostream that is connected to this LogStream object. It is synchronized so that not more than one LogMessage can be written at a time.

Parameters:
messageThe LogMessage to write.

Implements Arc::LogDestination.

Definition at line 209 of file Logger.cpp.

                                               {
    Glib::Mutex::Lock lock(mutex);
    const char *loc = NULL;
    if (!locale.empty()) {
      loc = setlocale(LC_ALL, NULL);
      setlocale(LC_ALL, locale.c_str());
    }
    destination << LoggerFormat(format) << message << std::endl;
    if (!locale.empty()) setlocale(LC_ALL, loc);
  }
void Arc::LogStream::operator= ( const LogStream unique) [private]

Private assignment operator.

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

Definition at line 227 of file Logger.cpp.

                                            {
    // Executing this code should be impossible!
    exit(EXIT_FAILURE);
  }
void Arc::LogDestination::setFormat ( const LogFormat newformat) [inherited]

Definition at line 197 of file Logger.cpp.

                                                           {
    format = newformat;
  }

Here is the caller graph for this function:


Member Data Documentation

std::ostream& Arc::LogStream::destination [private]

The ostream to which to write LogMessages.

This is the ostream to which LogMessages sent to this LogStream will be written.

Definition at line 280 of file Logger.h.

LogFormat Arc::LogDestination::format [protected, inherited]

Definition at line 222 of file Logger.h.

std::string Arc::LogDestination::locale [protected, inherited]

Definition at line 221 of file Logger.h.

Glib::Mutex Arc::LogStream::mutex [private]

A mutex for synchronization.

This mutex is locked before a LogMessage is written and it is not unlocked until the entire message has been written and the stream flushed. This is done in order to prevent LogMessages to appear mioxed in the stream.

Definition at line 288 of file Logger.h.


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