#include <LoggerHolder.h>
Part of API
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.
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; }
LoggerHolder logger (False); logger.addParent (parent.logger()); logger.logio() << "test1" << LogIO::POST; logger.logio() << "test2" << LogIO::POST;
This class simplifies and unifies all Image logging activities.
Definition at line 119 of file LoggerHolder.h.
| typedef LoggerHolderIterator | const_iterator |
| STL-style typedefs. | |
| const_iterator | begin () const |
| Get the begin and end iterator object. | |
| const_iterator | end () const |
Public Member Functions | |
| 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. | |
| 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. | |
| void | clear () |
| Clear the log. | |
| void | removeParents () |
| Remove all parents. | |
| const Block< LoggerHolder > & | parents () const |
| Return the block of parents. | |
| LogSink & | sink () |
| Get access to the log sink (reopen the log table if needed). | |
| const LogSink & | sink () const |
Private Attributes | |
| CountedPtr< LoggerHolderRep > | itsRep |
Create with a NullSink or MemoryLogSink (default).
Create with a TableLogSink.
| casa::LoggerHolder::LoggerHolder | ( | const LoggerHolder & | ) |
Copy constructor (reference sematics).
| casa::LoggerHolder::~LoggerHolder | ( | ) |
| LoggerHolder& casa::LoggerHolder::operator= | ( | const LoggerHolder & | ) |
Assignment (reference semantics).
| void casa::LoggerHolder::addParent | ( | const LoggerHolder & | ) |
Add a logger from a parent.
| void casa::LoggerHolder::append | ( | const LoggerHolder & | other | ) |
Append the entries of the other logger to this one.
Referenced by casa::ImageInterface< std::complex< Float > >::appendLog().
| void casa::LoggerHolder::reopenRW | ( | ) |
Reopen a readonly logtable for read/write (if needed).
| void casa::LoggerHolder::reopen | ( | ) | [inline] |
Reopen the log table if needed (after a tempClose).
Definition at line 545 of file LoggerHolder.h.
References itsRep.
Temporarily close all log tables.
By default the possible parent log tables are also closed.
| void casa::LoggerHolder::unlock | ( | ) |
Unlock the log table.
| void casa::LoggerHolder::flush | ( | ) |
Flush the log table.
| void casa::LoggerHolder::resync | ( | ) |
Resync the log table (if needed).
| Bool casa::LoggerHolder::isTempClosed | ( | ) | const [inline] |
Is the log table temporarily closed?
Definition at line 549 of file LoggerHolder.h.
References itsRep.
| LogIO & casa::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 553 of file LoggerHolder.h.
References itsRep.
Referenced by casa::ImageInterface< std::complex< Float > >::logSink().
| LogSink & casa::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 557 of file LoggerHolder.h.
References itsRep.
| const LogSink & casa::LoggerHolder::sink | ( | ) | const [inline] |
| void casa::LoggerHolder::clear | ( | ) |
Clear the log.
It removes the parents and removes all messages from the sink.
| void casa::LoggerHolder::removeParents | ( | ) |
Remove all parents.
| const Block< LoggerHolder > & casa::LoggerHolder::parents | ( | ) | const [inline] |
| LoggerHolder::const_iterator casa::LoggerHolder::begin | ( | ) | const [inline] |
| LoggerHolder::const_iterator casa::LoggerHolder::end | ( | ) | const [inline] |
Definition at line 573 of file LoggerHolder.h.
CountedPtr<LoggerHolderRep> casa::LoggerHolder::itsRep [private] |
Definition at line 207 of file LoggerHolder.h.
Referenced by isTempClosed(), logio(), parents(), reopen(), and sink().
1.5.1