casacore
Loading...
Searching...
No Matches
LogSinkInterface.h
Go to the documentation of this file.
1// # LogSinkInterface.h: Accepts LogMessages and posts them to some destination
2// # Copyright (C) 1996,2000,2001,2003
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_LOGSINKINTERFACE_H
27#define CASA_LOGSINKINTERFACE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Logging/LogFilterInterface.h>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// <summary>
36// Accepts LogMessages and posts them to some destination
37// </summary>
38
39// <use visibility=local>
40
41// <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLogging.cc" demos="dLogging.cc">
42// </reviewed>
43
44// <prerequisite>
45// <li> <linkto class=LogMessage>LogMessage</linkto>
46// <li> <linkto class=LogFilterInterface>LogFilterInterface</linkto>
47// </prerequisite>
48//
49// <etymology>
50// Log as in "Log Book." Sink from its common usage ("source/sink") as a thing
51// which can accept some substance or energy. Interface because this is an
52// abstract, not concrete, class.
53// </etymology>
54//
55// <synopsis>
56// This abstract base class is not intended for applications programmers.
57// Instead they should look at <linkto class=LogSink>LogSink</linkto>.
58//
59// This class defines a minimal "posting" interface for all objects which accept
60// log messages. The fundamental model of a <src>LogSinkInterface</src> is:
61// <ol>
62// <li> That it contains a
63// <linkto class=LogFilterInterface>LogFilterInterface</linkto> that is
64// used to accept or reject messages; and
65// <li> That it has a post message that takes a log message; and, if it passes
66// the filter, does something with it (prints it to a stream, saves it to
67// a table, ...).
68// </ol>
69// There is no notion of local vs global sinks - that is imposed by
70// <src>LogSink</src>.
71// </synopsis>
72//
73// <example>
74// <srcblock>
75// LogSinkInterface &ref = ...;
76// LogMessage message(...);
77// ref.postLocally(message);
78// if (ref.filter().lowestPriority() != LogMessage::DEBUGGING) {
79// ref.filter(LogMessage::DEBUGGING);
80// }
81// </srcblock>
82// For a more complete example see <linkto file="Logging.h">Logging.h</linkto>.
83// </example>
84//
85// <motivation>
86// Make it straightforward to extend the number of places a message may be
87// in the future through derivation.
88// </motivation>
89//
90// <todo asof="1996/07/24">
91// <li> Nothing known.
92// </todo>
93
95 public:
96 // Create with a <src>NORMAL</src> filter.
98 // Create with the supplied <src>filter</src>.
100
101 // Copy semantics - copy the filter from <src>other</src> to <src>this</src>
102 // <group>
105 // </group>
106
108
109 // Get/set the filter.
110 // <group>
111 virtual const LogFilterInterface &filter() const;
113 // </group>
114
115 // Get number of messages in sink.
116 virtual uInt nelements() const;
117
118 // Get given part of the i-th message from the sink.
119 // <group>
120 virtual Double getTime(uInt i) const;
121 virtual String getPriority(uInt i) const;
122 virtual String getMessage(uInt i) const;
123 virtual String getLocation(uInt i) const;
124 virtual String getObjectID(uInt i) const;
125 // </group>
126
127 // This function must be over-ridden in derived classes. If the filter
128 // passes the message, do what is necessary with the message and return
129 // <src>True</src>.
130 virtual Bool postLocally(const LogMessage &message) = 0;
131
132 // Write any pending output.
133 virtual void flush(Bool global = True);
134
135 // Write a message (usually from another logsink) into the local one.
136 // The default implementation does nothing.
137 virtual void writeLocally(Double time, const String &message, const String &priority,
138 const String &location, const String &objectID);
139
140 // Clear the local sink (i.e. remove all messages from it).
141 // The default implementation does nothing.
142 virtual void clearLocally();
143
144 // Returns the id for this class...
145 static String localId();
146 // Returns the id of the LogSink in use...
147 virtual String id() const = 0;
148 // Write to cerr too
149 virtual void cerrToo(bool cerr2);
150 void setTaskName(const String &theTask) { taskName = theTask; }
151
152 private:
154
155 protected:
157};
158
159} // namespace casacore
160
161#endif
LogSinkInterface(const LogSinkInterface &other)
Copy semantics - copy the filter from other to this.
LogSinkInterface & operator=(const LogSinkInterface &)
virtual LogSinkInterface & filter(const LogFilterInterface &filter)
virtual void cerrToo(bool cerr2)
Write to cerr too.
virtual String getPriority(uInt i) const
LogFilterInterface * filter_p
virtual Double getTime(uInt i) const
Get given part of the i-th message from the sink.
virtual void flush(Bool global=True)
Write any pending output.
LogSinkInterface()
Create with a NORMAL filter.
virtual Bool postLocally(const LogMessage &message)=0
This function must be over-ridden in derived classes.
virtual String getLocation(uInt i) const
LogSinkInterface(const LogFilterInterface &filter)
Create with the supplied filter.
virtual const LogFilterInterface & filter() const
Get/set the filter.
virtual void writeLocally(Double time, const String &message, const String &priority, const String &location, const String &objectID)
Write a message (usually from another logsink) into the local one.
virtual String id() const =0
Returns the id of the LogSink in use...
virtual String getObjectID(uInt i) const
virtual String getMessage(uInt i) const
void setTaskName(const String &theTask)
virtual uInt nelements() const
Get number of messages in sink.
static String localId()
Returns the id for this class...
virtual void clearLocally()
Clear the local sink (i.e.
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
TableExprNode time(const TableExprNode &node)
Definition ExprNode.h:1368
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53