casacore
Public Types | Public Member Functions | Private Attributes | List of all members
casacore::LoggerHolder Class Reference

More...

#include <LoggerHolder.h>

Public Types

typedef LoggerHolderIterator const_iterator
 Define the STL-style iterators. More...
 

Public Member Functions

 LoggerHolder (Bool nullSink=False)
 Create with a NullSink or MemoryLogSink (default). More...
 
 LoggerHolder (const String &logTableName, Bool isWritable)
 Create with a TableLogSink. More...
 
 LoggerHolder (const LoggerHolder &)
 Copy constructor (reference sematics). More...
 
 ~LoggerHolder ()
 
LoggerHolderoperator= (const LoggerHolder &)
 Assignment (reference semantics). More...
 
void addParent (const LoggerHolder &)
 Add a logger from a parent. More...
 
void append (const LoggerHolder &other)
 Append the entries of the other logger to this one. More...
 
void reopenRW ()
 Reopen a readonly logtable for read/write (if needed). More...
 
void reopen ()
 Reopen the log table if needed (after a tempClose). More...
 
void tempClose (Bool closeParents=True) const
 Temporarily close all log tables. More...
 
void unlock ()
 Unlock the log table. More...
 
void flush ()
 Flush the log table. More...
 
void resync ()
 Resync the log table (if needed). More...
 
Bool isTempClosed () const
 Is the log table temporarily closed? More...
 
LogIOlogio ()
 Get access to the logger. More...
 
LogSinksink ()
 Get access to the log sink (reopen the log table if needed). More...
 
const LogSinksink () const
 
void clear ()
 Clear the log. More...
 
void removeParents ()
 Remove all parents. More...
 
const Block< LoggerHolder > & parents () const
 Return the block of parents. More...
 
const_iterator begin () const
 Get the begin and end iterator object. More...
 
const_iterator end () const
 

Private Attributes

CountedPtr< LoggerHolderRepitsRep
 

Detailed Description

Class holding a hierarchy of loggers.

Intended use:

Public interface

Review Status

Test programs:
tLoggerHolder

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 LoggerHolderRep) 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;
}
@ POST
Post the accumulated message.
Definition: LogIO.h:173
LoggerHolderIterator const_iterator
Define the STL-style iterators.
Definition: LoggerHolder.h:201
LoggerHolder(Bool nullSink=False)
Create with a NullSink or MemoryLogSink (default).
const Bool True
Definition: aipstype.h:43

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.

logger.addParent (parent.logger());
logger.logio() << "test1" << LogIO::POST;
logger.logio() << "test2" << LogIO::POST;
const Bool False
Definition: aipstype.h:44

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.

Definition at line 120 of file LoggerHolder.h.

Member Typedef Documentation

◆ const_iterator

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;
}


STL-style typedefs.

Definition at line 201 of file LoggerHolder.h.

Constructor & Destructor Documentation

◆ LoggerHolder() [1/3]

casacore::LoggerHolder::LoggerHolder ( Bool  nullSink = False)
explicit

Create with a NullSink or MemoryLogSink (default).

◆ LoggerHolder() [2/3]

casacore::LoggerHolder::LoggerHolder ( const String logTableName,
Bool  isWritable 
)

Create with a TableLogSink.

◆ LoggerHolder() [3/3]

casacore::LoggerHolder::LoggerHolder ( const LoggerHolder )

Copy constructor (reference sematics).

◆ ~LoggerHolder()

casacore::LoggerHolder::~LoggerHolder ( )

Member Function Documentation

◆ addParent()

void casacore::LoggerHolder::addParent ( const LoggerHolder )

Add a logger from a parent.

◆ append()

void casacore::LoggerHolder::append ( const LoggerHolder other)

Append the entries of the other logger to this one.

Referenced by casacore::ImageInterface< T >::appendLog().

◆ begin()

LoggerHolder::const_iterator casacore::LoggerHolder::begin ( ) const
inline

Get the begin and end iterator object.

Definition at line 570 of file LoggerHolder.h.

◆ clear()

void casacore::LoggerHolder::clear ( )

Clear the log.

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

◆ end()

LoggerHolder::const_iterator casacore::LoggerHolder::end ( ) const
inline

Definition at line 574 of file LoggerHolder.h.

◆ flush()

void casacore::LoggerHolder::flush ( )

Flush the log table.

◆ isTempClosed()

Bool casacore::LoggerHolder::isTempClosed ( ) const
inline

Is the log table temporarily closed?

Definition at line 550 of file LoggerHolder.h.

References itsRep.

◆ logio()

LogIO & casacore::LoggerHolder::logio ( )
inline

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).

Definition at line 554 of file LoggerHolder.h.

References itsRep.

Referenced by casacore::ImageInterface< T >::logSink().

◆ operator=()

LoggerHolder& casacore::LoggerHolder::operator= ( const LoggerHolder )

Assignment (reference semantics).

◆ parents()

const Block< LoggerHolder > & casacore::LoggerHolder::parents ( ) const
inline

Return the block of parents.

Definition at line 566 of file LoggerHolder.h.

References itsRep.

◆ removeParents()

void casacore::LoggerHolder::removeParents ( )

Remove all parents.

◆ reopen()

void casacore::LoggerHolder::reopen ( )
inline

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

Definition at line 546 of file LoggerHolder.h.

References itsRep.

◆ reopenRW()

void casacore::LoggerHolder::reopenRW ( )

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

◆ resync()

void casacore::LoggerHolder::resync ( )

Resync the log table (if needed).

◆ sink() [1/2]

LogSink & casacore::LoggerHolder::sink ( )
inline

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.

Definition at line 558 of file LoggerHolder.h.

References itsRep.

◆ sink() [2/2]

const LogSink & casacore::LoggerHolder::sink ( ) const
inline

Definition at line 562 of file LoggerHolder.h.

References itsRep.

◆ tempClose()

void casacore::LoggerHolder::tempClose ( Bool  closeParents = True) const

Temporarily close all log tables.

By default the possible parent log tables are also closed.

◆ unlock()

void casacore::LoggerHolder::unlock ( )

Unlock the log table.

Member Data Documentation

◆ itsRep

CountedPtr<LoggerHolderRep> casacore::LoggerHolder::itsRep
private

Definition at line 208 of file LoggerHolder.h.

Referenced by isTempClosed(), logio(), parents(), reopen(), and sink().


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