LoggerHolder.h

Classes

LoggerHolder -- Class holding a hierarchy of loggers. (full description)
LoggerHolderRep -- Representation of the class holding a hierarchy of loggers. (full description)
LogHolderIterEntry -- Class representing an entry in a LoggerHolder. (full description)
LogHolderIter -- Class doing the actual iteration through an LoggerHolder. (full description)
LoggerHolderIterator -- Class to iterate through an LoggerHolder. (full description)

class LoggerHolder

Interface

Public Members
explicit LoggerHolder (Bool nullSink = False)
LoggerHolder (const String& logTableName, Bool isWritable)
LoggerHolder (const LoggerHolder&)
~LoggerHolder()
LoggerHolder& operator= (const LoggerHolder&)
void addParent (const LoggerHolder&)
void append (const LoggerHolder& other)
void reopenRW()
void reopen()
void tempClose (Bool closeParents = True) const
void unlock()
void flush()
void resync()
Bool isTempClosed() const
LogIO& logio()
LogSink& sink()
const LogSink& sink() const
void clear()
void removeParents()
const Block<LoggerHolder>& parents() const
const_iterator begin() const
const_iterator end() const

Description

Review Status

Programs:
Tests:

Prerequisite

Synopsis

The LoggerHolder class implements a hierarchy of loggers. It has a log sink of its own and can have multiple parent LoggerHolder objects representing the log info of parent objects. It is used by class ImageInterface, but could also be used elsewhere.

The sink of a LoggerHolder can be different depending on the type of image. E.g. for a transient image it can be a MemoryLogSink, while for a persistent image it will be a TableLogSink.
An important feature is that an LoggerHolder can have zero or more parent LoggerHolder objects. In that way the log of the parent object of an image object can be made part of the log of the image object itself, without having to copy the log.

To iterate through all messages in a LoggerHolder (including all parents), the LoggerHolderIterator can be used. This is an STL-style const_iterator object.

LoggerHolder uses reference counting (of class ) to be able to retain the object after the (ImageInterface) object containing it is gone. Otherwise classes like SubImage would lose their log info.

Example

  LoggerHolder logger ("tLoggerHolder_tmp.log", True);
  logger.logio() << "test1" << LogIO::POST;
  logger.logio() << "test2" << LogIO::POST;
  for (LoggerHolder::const_iterator iter = logger.begin();
       iter != logger.end();
       iter++) {
    cout << iter->time() << ' ' << iter->message() << endl;
  }
This example shows the construction of an LoggerHolder with a TableLogSink sink. Thereafter some messages are written. The latter part shows how to iterate through all messages.

  LoggerHolder logger (False);
  logger.addParent (parent.logger());
  logger.logio() << "test1" << LogIO::POST;
  logger.logio() << "test2" << LogIO::POST;
This example shows the construction of an LoggerHolder with a MemoryLogSink sink (e.g. for a SubImage). Thereafter the logger of the parent image is added to it. Finally some messages are written.

Motivation

This class simplifies and unifies all Image logging activities.

Member Description

explicit LoggerHolder (Bool nullSink = False)

Create with a NullSink or MemoryLogSink (default).

LoggerHolder (const String& logTableName, Bool isWritable)

Create with a TableLogSink.

LoggerHolder (const LoggerHolder&)

Copy constructor (reference sematics).

~LoggerHolder()

LoggerHolder& operator= (const LoggerHolder&)

Assignment (reference semantics).

void addParent (const LoggerHolder&)

Add a logger from a parent.

void append (const LoggerHolder& other)

Append the entries of the other logger to this one.

void reopenRW()

Reopen a readonly logtable for read/write (if needed).

void reopen()

Reopen the log table if needed (after a tempClose).

void tempClose (Bool closeParents = True) const

Temporarily close all log tables. By default the possible parent log tables are also closed.

void unlock()

Unlock the log table.

void flush()

Flush the log table.

void resync()

Resync the log table (if needed).

Bool isTempClosed() const

Is the log table temporarily closed?

LogIO& logio()

Get access to the logger. It assumes that it will be used to post a message, so it reopens the log table for read/write if needed).

LogSink& sink()
const LogSink& sink() const

Get access to the log sink (reopen the log table if needed). It is not assumed you want to write. If you want to do that, you should first call reopenRW() to ensure you can write.

void clear()

Clear the log. It removes the parents and removes all messages from the sink.

void removeParents()

Remove all parents.

const Block<LoggerHolder>& parents() const

Return the block of parents.

const_iterator begin() const

Define the STL-style iterators. Only a const forward iterator is available. It makes it possible to iterate through all messages in the logger.

  LoggerHolder logger("log.name", False)
  for (LoggerHolder::const_iterator iter=arr.begin();
       iter!=arr.end(); iter++) {
    cout << iter.message() << endl;
  }

Get the begin and end iterator object.

const_iterator end() const

Define the STL-style iterators. Only a const forward iterator is available. It makes it possible to iterate through all messages in the logger.

  LoggerHolder logger("log.name", False)
  for (LoggerHolder::const_iterator iter=arr.begin();
       iter!=arr.end(); iter++) {
    cout << iter.message() << endl;
  }

class LoggerHolderRep

Interface

LoggerHolderRep (Bool nullSink)
LoggerHolderRep (const String& logTableName, Bool isWritable)
LoggerHolderRep (const LoggerHolderRep&)
~LoggerHolderRep()
LoggerHolderRep& operator= (const LoggerHolderRep&)
void addParent (const LoggerHolder&)
void append (const LoggerHolder& other)
void reopenRW()
void reopen()
void tempClose (Bool closeParents = True)
void unlock()
void flush()
void resync()
Bool isTempClosed() const
LogIO& logio()
LogSink& sink()
void clear()
void removeParents()
const Block<LoggerHolder>& parents() const
const_iterator begin() const
const_iterator end() const
Private Members
void doReopen()

Description

Review Status

Programs:
Tests:
  • tLoggerHolder.cc

Prerequisite

Synopsis

The LoggerHolderRep class is the reference counted implementation of LoggerHolder. See that class for more information.

Motivation

Reference counting was needed to be able to keep a LoggerHolder object after the (ImageInterface) object containing it is gone.

Member Description

LoggerHolderRep (Bool nullSink)

Create with a NullSink or MemoryLogSink (default).

LoggerHolderRep (const String& logTableName, Bool isWritable)

Create with a TableLogSink.

LoggerHolderRep (const LoggerHolderRep&)

Copy constructor.

~LoggerHolderRep()

LoggerHolderRep& operator= (const LoggerHolderRep&)

Assignment. It removes the current parents.

void addParent (const LoggerHolder&)

Add a logger from a parent.

void append (const LoggerHolder& other)

Append the entries of the other logger to this one.

void reopenRW()

Reopen a readonly logtable for read/write (if needed).

void reopen()

Reopen the log table if needed (after a tempClose).

void tempClose (Bool closeParents = True)

Temporarily close all log tables. By default the possible parent log tables are also closed.

void unlock()

Unlock the log table.

void flush()

Flush the log table.

void resync()

Resync the log table (if needed).

Bool isTempClosed() const

Is the log table temporarily closed?

LogIO& logio()

Get access to the logger. It assumes that it will be used to post a message, so it reopens the log table for read/write if needed).

LogSink& sink()

Get access to the log sink (reopen the log table if needed). It is not assumed you want to write. If you want to do that, you should first call reopenRW() to ensure you can write.

void clear()

Clear the log. It removes the parents and removes all messages from the sink.

void removeParents()

Remove all parents.

const Block<LoggerHolder>& parents() const

Return the block of parents.

const_iterator begin() const

Define the STL-style iterators. Only a const forward iterator is available. It makes it possible to iterate through all messages in the logger.

  LoggerHolder logger("log.name", False)
  for (LoggerHolder::const_iterator iter=arr.begin();
       iter!=arr.end(); iter++) {
    cout << iter.message() << endl;
  }

Get the begin and end iterator object.

const_iterator end() const

Define the STL-style iterators. Only a const forward iterator is available. It makes it possible to iterate through all messages in the logger.

  LoggerHolder logger("log.name", False)
  for (LoggerHolder::const_iterator iter=arr.begin();
       iter!=arr.end(); iter++) {
    cout << iter.message() << endl;
  }

void doReopen()

Do the actual reopen.

class LogHolderIterEntry

Interface

Public Members
LogHolderIterEntry() : itsSink(0), itsIndex(0)
LogHolderIterEntry (const LogSink* sink, uInt index) : itsSink(sink), itsIndex(index)
LogHolderIterEntry (const LogHolderIterEntry& that) : itsSink(that.itsSink), itsIndex(that.itsIndex)
~LogHolderIterEntry()
LogHolderIterEntry& operator= (const LogHolderIterEntry& that)
Double time() const
String message() const
String priority() const
String location() const
String objectID() const

Description

Review Status

Programs:
Tests:
  • tLoggerHolder.cc

Prerequisite

Synopsis

This class makes it possible to use the iterator in the STL-style. It only contains a 'pointer' to the current entry in the current logger. Function like time() can be used to retrieve the message parts.

Member Description

LogHolderIterEntry() : itsSink(0), itsIndex(0)

LogHolderIterEntry (const LogSink* sink, uInt index) : itsSink(sink), itsIndex(index)

LogHolderIterEntry (const LogHolderIterEntry& that) : itsSink(that.itsSink), itsIndex(that.itsIndex)

~LogHolderIterEntry()

LogHolderIterEntry& operator= (const LogHolderIterEntry& that)

Double time() const
String message() const
String priority() const
String location() const
String objectID() const

Get the message parts.


class LogHolderIter

Interface

LogHolderIter (const LoggerHolder*)
~LogHolderIter()
Bool next()
const LogHolderIterEntry& getEntry() const
const LoggerHolder& logger() const
Private Members
LogHolderIter (const LogHolderIter&)
LogHolderIter& operator= (const LogHolderIter&)

Description

Review Status

Programs:
Tests:
  • tLoggerHolder.cc

Prerequisite

Synopsis

This class makes it possible to use the iterator in the STL-style. It is used by LoggerHolderIterator which is the class as seen by the user. LogHolderIter makes it easier to make the first entry available on construction of an LoggerHolderIterator.

Member Description

LogHolderIter (const LoggerHolder*)

Construct the iterator on the given LoggerHolderRep.

~LogHolderIter()

Bool next()

Increment to next message. Returns False if at the end.

const LogHolderIterEntry& getEntry() const

Get the entry.

const LoggerHolder& logger() const

LogHolderIter (const LogHolderIter&)

Copy constructor is not needed, thus forbidden.

LogHolderIter& operator= (const LogHolderIter&)

Assignment is not needed, thus forbidden.


class LoggerHolderIterator

Interface

Public Members
LoggerHolderIterator() : itsIter(0), itsNotAtEnd(False)
LoggerHolderIterator (const LoggerHolder*)
LoggerHolderIterator (const LoggerHolderIterator&)
~LoggerHolderIterator()
LoggerHolderIterator& operator= (const LoggerHolderIterator&)
void operator++()
void operator++ (int)
Bool operator!= (const LoggerHolderIterator& that)
const LogHolderIterEntry& operator*() const
const LogHolderIterEntry* operator->() const
const LoggerHolder& logger() const
Private Members
void next()

Description

Review Status

Programs:
Tests:
  • tLoggerHolder.cc

Prerequisite

Synopsis

This class makes it possible to iterate in the STL-style through all entries of an LoggerHolder object. If the logger has parent LoggerHolder objects, it first iterates through all parents (recursively) and finally through all entries in the LoggerHolder object itself.

Example

  LoggerHolder logger ("tLoggerHolder_tmp.log", True);
  logger.logio() << "test1" << LogIO::POST;
  logger.logio() << "test2" << LogIO::POST;
  for (LoggerHolder::const_iterator iter = logger.begin();
       iter != logger.end();
       iter++) {
    cout << iter->time() << ' ' << iter->message() << endl;
  }

Member Description

LoggerHolderIterator() : itsIter(0), itsNotAtEnd(False)

LoggerHolderIterator (const LoggerHolder*)

LoggerHolderIterator (const LoggerHolderIterator&)

~LoggerHolderIterator()

LoggerHolderIterator& operator= (const LoggerHolderIterator&)

void operator++()
void operator++ (int)

Increment to next message.

Bool operator!= (const LoggerHolderIterator& that)

Is the iterator not at the end yet?

const LogHolderIterEntry& operator*() const
const LogHolderIterEntry* operator->() const

Get the entry.

const LoggerHolder& logger() const

void next()

Get the next entry (if available).