casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@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 //#
27 //# $Id$
28 
29 #ifndef CASA_LOGSINKINTERFACE_H
30 #define CASA_LOGSINKINTERFACE_H
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
35 
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 // <summary>
40 //Accepts LogMessages and posts them to some destination
41 // </summary>
42 
43 // <use visibility=local>
44 
45 // <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLogging.cc" demos="dLogging.cc">
46 // </reviewed>
47 
48 // <prerequisite>
49 // <li> <linkto class=LogMessage>LogMessage</linkto>
50 // <li> <linkto class=LogFilterInterface>LogFilterInterface</linkto>
51 // </prerequisite>
52 //
53 // <etymology>
54 // Log as in "Log Book." Sink from its common usage ("source/sink") as a thing
55 // which can accept some substance or energy. Interface because this is an
56 // abstract, not concrete, class.
57 // </etymology>
58 //
59 // <synopsis>
60 // This abstract base class is not intended for applications programmers.
61 // Instead they should look at <linkto class=LogSink>LogSink</linkto>.
62 //
63 // This class defines a minimal "posting" interface for all objects which accept
64 // log messages. The fundamental model of a <src>LogSinkInterface</src> is:
65 // <ol>
66 // <li> That it contains a
67 // <linkto class=LogFilterInterface>LogFilterInterface</linkto> that is
68 // used to accept or reject messages; and
69 // <li> That it has a post message that takes a log message; and, if it passes
70 // the filter, does something with it (prints it to a stream, saves it to
71 // a table, ...).
72 // </ol>
73 // There is no notion of local vs global sinks - that is imposed by
74 // <src>LogSink</src>.
75 // </synopsis>
76 //
77 // <example>
78 // <srcblock>
79 // LogSinkInterface &ref = ...;
80 // LogMessage message(...);
81 // ref.postLocally(message);
82 // if (ref.filter().lowestPriority() != LogMessage::DEBUGGING) {
83 // ref.filter(LogMessage::DEBUGGING);
84 // }
85 // </srcblock>
86 // For a more complete example see <linkto file="Logging.h">Logging.h</linkto>.
87 // </example>
88 //
89 // <motivation>
90 // Make it straightforward to extend the number of places a message may be
91 // in the future through derivation.
92 // </motivation>
93 //
94 // <todo asof="1996/07/24">
95 // <li> Nothing known.
96 // </todo>
97 
98 
100 {
101 public:
102  // Create with a <src>NORMAL</src> filter.
104  // Create with the supplied <src>filter</src>.
106 
107  // Copy semantics - copy the filter from <src>other</src> to <src>this</src>
108  // <group>
109  LogSinkInterface(const LogSinkInterface &other);
111  // </group>
112 
113  virtual ~LogSinkInterface();
114 
115  // Get/set the filter.
116  // <group>
117  virtual const LogFilterInterface &filter() const;
118  virtual LogSinkInterface &filter(const LogFilterInterface &filter);
119  // </group>
120 
121  // Get number of messages in sink.
122  virtual uInt nelements() const;
123 
124  // Get given part of the i-th message from the sink.
125  // <group>
126  virtual Double getTime (uInt i) const;
127  virtual String getPriority (uInt i) const;
128  virtual String getMessage (uInt i) const;
129  virtual String getLocation (uInt i) const;
130  virtual String getObjectID (uInt i) const;
131  // </group>
132 
133  // This function must be over-ridden in derived classes. If the filter
134  // passes the message, do what is necessary with the message and return
135  // <src>True</src>.
136  virtual Bool postLocally(const LogMessage &message)= 0;
137 
138  // Write any pending output.
139  virtual void flush (Bool global=True);
140 
141  // Write a message (usually from another logsink) into the local one.
142  // The default implementation does nothing.
143  virtual void writeLocally (Double time, const String& message,
144  const String& priority, const String& location,
145  const String& objectID);
146 
147  // Clear the local sink (i.e. remove all messages from it).
148  // The default implementation does nothing.
149  virtual void clearLocally();
150 
151  // Returns the id for this class...
152  static String localId( );
153  // Returns the id of the LogSink in use...
154  virtual String id( ) const = 0;
155  // Write to cerr too
156  virtual void cerrToo(bool cerr2);
157  void setTaskName(const String &theTask){taskName=theTask;}
158 private:
160 protected:
162 };
163 
164 
165 
166 } //# NAMESPACE CASACORE - END
167 
168 #endif
void setTaskName(const String &theTask)
static String localId()
Returns the id for this class...
Abstract base class for filtering LogMessages.
TableExprNode time(const TableExprNode &node)
Definition: ExprNode.h:1537
virtual void flush(Bool global=True)
Write any pending output.
virtual String getLocation(uInt i) const
LogFilterInterface * filter_p
Accepts LogMessages and posts them to some destination.
double Double
Definition: aipstype.h:55
virtual void clearLocally()
Clear the local sink (i.e.
virtual String id() const =0
Returns the id of the LogSink in use...
virtual void cerrToo(bool cerr2)
Write to cerr too.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual const LogFilterInterface & filter() const
Get/set the filter.
virtual uInt nelements() const
Get number of messages in sink.
LogSinkInterface & operator=(const LogSinkInterface &)
virtual String getObjectID(uInt i) const
virtual String getMessage(uInt i) const
virtual Double getTime(uInt i) const
Get given part of the i-th message from the sink.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual Bool postLocally(const LogMessage &message)=0
This function must be over-ridden in derived classes.
virtual String getPriority(uInt i) const
const Bool True
Definition: aipstype.h:43
Informational log messages with with time, priority, and origin.
Definition: LogMessage.h:101
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.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
LogSinkInterface()
Create with a NORMAL filter.