casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TableLogSink.h
Go to the documentation of this file.
1 //# TableLogSink.h: Save log messages in a Casacore Table
2 //# Copyright (C) 1996,1997,1998,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 TABLES_TABLELOGSINK_H
30 #define TABLES_TABLELOGSINK_H
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
41 
42 namespace casacore { //# NAMESPACE CASACORE - BEGIN
43 
44 //# Forward Declarations
45 class TableDesc;
46 class SetupNewTable;
47 
48 // <summary>
49 // Save log messages in a Casacore Table
50 // </summary>
51 
52 // <use visibility=export>
53 
54 // <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLogging.cc" demos="dLogging.cc">
55 // </reviewed>
56 
57 // <prerequisite>
58 // <li> <linkto class=LogSinkInterface>LogSinkInterface</linkto>
59 // <li> <linkto module=Tables>Tables</linkto>
60 // </prerequisite>
61 //
62 // <etymology>
63 // Log to a Casacore Table.
64 // </etymology>
65 //
66 // <synopsis>
67 // Unlike the other classes derived from
68 // <linkto class=LogSinkInterface>LogSinkInterface</linkto>, there are utility
69 // functions in this class which might be of some modest interest. In
70 // particular, the member functions which define the structure of the table
71 // and define the column names might be of interest.
72 //
73 // This class posts messages which pass the filter to a Casacore
74 // <linkto class=Table>Table</linkto>. It puts every field of the
75 // <linkto class=LogMessage>LogMessage</linkto> into its own column.
76 // </synopsis>
77 //
78 // <example>
79 // See <linkto file="Logging.h">Logging.h</linkto>.
80 // </example>
81 //
82 // <motivation>
83 // "Persistent" log messages must be stored in a Table.
84 // </motivation>
85 //
86 // <todo asof="2001/06/12">
87 // <li> Allow a subset of the columns to be written? e.g., only time,
88 // message, and priority.
89 // <li> Allow time sorting in concatenate?
90 // </todo>
91 
93 {
94 public:
95  // If <src>fileName</src> exists, attach and append to it, otherwise create
96  // a table with that name. If the table exists, it must have all the
97  // required columns defined by <src>logTableDescription()</src>.
98  // <group>
100  TableLogSink (const LogFilterInterface& filter, const String& fileName);
101  // </group>
102 
103  // Open the log table for readonly.
104  // If needed, reopenRW can be used later to define a filter and
105  // to open the logtable for writing.
106  explicit TableLogSink (const String& fileName);
107 
108  // After copying, both sinks will write to the same <src>Table</src>.
109  // <group>
110  TableLogSink (const TableLogSink& other);
111  TableLogSink& operator= (const TableLogSink& other);
112  // </group>
113 
114  ~TableLogSink();
115 
116  // Reopen the logtable for read/write (if needed).
117  // When it actually reopens, the given filter will be used.
118  void reopenRW (const LogFilterInterface& filter);
119 
120  // If the message passes the filter, write it to the log table.
121  virtual Bool postLocally (const LogMessage& message);
122 
123  // Get number of messages in sink.
124  virtual uInt nelements() const;
125 
126  // Get given part of the i-th message from the sink.
127  // <group>
128  virtual Double getTime (uInt i) const;
129  virtual String getPriority (uInt i) const;
130  virtual String getMessage (uInt i) const;
131  virtual String getLocation (uInt i) const;
132  virtual String getObjectID (uInt i) const;
133  // </group>
134 
135  // Access to the actual log table and its columns.
136  // <note role=caution>
137  // Functions <src>time, priority, message, location, objectID</src>
138  // return a null <src>ScalarColumn</src> object when the logtable is
139  // not writable. Using it may result in using a null pointer
140  // causing a core dump. In debug mode it is checked if the object
141  // is not null.
142  // </note>
143  // <group>
144  const Table& table() const;
145  Table& table();
146  const ScalarColumn<Double>& roTime() const;
148  const ScalarColumn<String>& roPriority() const;
150  const ScalarColumn<String>& roMessage() const;
152  const ScalarColumn<String>& roLocation() const;
154  const ScalarColumn<String>& roObjectID() const;
156  // </group>
157 
158  // Defines the minimal set of columns in the table (more may exist, but
159  // are ignored.
160  enum Columns {
161  // MJD in seconds, UT. (Double.)
163  // Message importance. (String).
165  // Informational message. (String).
167  // Source code origin of the log message. Usually a combination of
168  // class name, method name, file name and line number, but any String
169  // is legal.
171  // ObjectID of distributed object that created the message (String).
172  // If empty, no OBJECT_ID was set.
174  };
175 
176  // Turn the <src>Columns</src> enum into a String which is the actual
177  // column name in the <src>Table</src>.
178  static String columnName(Columns which);
179 
180  // Description of the log table. You can use this if, e.g., you do not
181  // want to use the storage managers that this class creates by default
182  // (currently Miriad).
184 
185  // Write out any pending output to the table.
186  virtual void flush (Bool global=True);
187 
188  // Write a message (usually from another logsink) into the local one.
189  virtual void writeLocally (Double time, const String& message,
190  const String& priority, const String& location,
191  const String& objectID);
192 
193  // Clear the local sink (i.e. remove all messages from it).
194  virtual void clearLocally();
195 
196  // Returns the id for this class...
197  static String localId( );
198  // Returns the id of the LogSink in use...
199  String id( ) const;
200 
201  // Make a LogSink for a TableLogSink with a new table.
202  // Default filter is <src>NORMAL</src>.
203  // <group>
204  static LogSink makeSink (const String& fileName);
205  static LogSink makeSink (LogMessage::Priority filter,
206  const String& fileName);
207  static LogSink makeSink (const LogFilterInterface& filter,
208  const String& fileName);
209  // </group>
210 
211 private:
212  // Undefined and inaccessible
213  TableLogSink();
214  // Avoid duplicating code in copy ctor and assignment operator
215  void copy_other(const TableLogSink& other);
216  // Make a new log table.
217  void makeTable (SetupNewTable&);
218  // Attach the column objects and create unit keywor if needed.
219  void attachCols();
220  // Initialize the object.
221  void init (const String& fileName);
222 
223 
228  // Origin
230  // ObjectID
232 };
233 
234 //# Inlines
235 inline const Table& TableLogSink::table() const {return log_table_p;}
237 
239  {return time_p;}
241  {return time_p;}
243  {return priority_p;}
245  {return priority_p;}
247  {return location_p;}
249  {return location_p;}
251  {return id_p;}
253  {return id_p;}
255  {return message_p;}
257  {return message_p;}
258 
259 inline LogSink TableLogSink::makeSink (const String& fileName)
260  { return makeSink (LogFilter(), fileName); }
262  const String& fileName)
263  { return makeSink (LogFilter(filter), fileName); }
264 
265 
266 
267 } //# NAMESPACE CASACORE - END
268 
269 #endif
virtual Bool postLocally(const LogMessage &message)
If the message passes the filter, write it to the log table.
virtual uInt nelements() const
Get number of messages in sink.
virtual String getObjectID(uInt i) const
void init(const String &fileName)
Initialize the object.
const ScalarColumn< String > & roMessage() const
Definition: TableLogSink.h:254
ScalarColumn< Double > time_p
Definition: TableLogSink.h:225
Source code origin of the log message.
Definition: TableLogSink.h:170
const ScalarColumn< String > & roObjectID() const
Definition: TableLogSink.h:250
ScalarColumn< Double > & time()
Definition: TableLogSink.h:240
Abstract base class for filtering LogMessages.
const Table & table() const
Access to the actual log table and its columns.
Definition: TableLogSink.h:235
Create a new table - define shapes, data managers, etc.
Definition: SetupNewTab.h:340
ObjectID of distributed object that created the message (String).
Definition: TableLogSink.h:173
const ScalarColumn< String > & roLocation() const
Definition: TableLogSink.h:246
Main interface class to a read/write table.
Definition: Table.h:157
ScalarColumn< String > id_p
ObjectID.
Definition: TableLogSink.h:231
void copy_other(const TableLogSink &other)
Avoid duplicating code in copy ctor and assignment operator.
ScalarColumn< String > & message()
Definition: TableLogSink.h:256
TableLogSink & operator=(const TableLogSink &other)
virtual String getPriority(uInt i) const
static String localId()
Returns the id for this class...
TableLogSink()
Undefined and inaccessible.
virtual String getLocation(uInt i) const
Accepts LogMessages and posts them to some destination.
ScalarColumn< String > message_p
Definition: TableLogSink.h:227
virtual String getMessage(uInt i) const
virtual Double getTime(uInt i) const
Get given part of the i-th message from the sink.
ScalarColumn< String > & location()
Definition: TableLogSink.h:248
ScalarColumn< String > location_p
Origin.
Definition: TableLogSink.h:229
Save log messages in a Casacore Table.
Definition: TableLogSink.h:92
static TableDesc logTableDescription()
Description of the log table.
Filter LogMessages on message priority.
Definition: LogFilter.h:84
double Double
Definition: aipstype.h:55
ScalarColumn< String > & objectID()
Definition: TableLogSink.h:252
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual const LogFilterInterface & filter() const
Get/set the filter.
Columns
Defines the minimal set of columns in the table (more may exist, but are ignored. ...
Definition: TableLogSink.h:160
virtual void flush(Bool global=True)
Write out any pending output to the table.
ScalarColumn< String > priority_p
Definition: TableLogSink.h:226
std::set< ScanKey > filter(const std::set< ScanKey > scans, const ArrayKey &arrayKey)
given a set of scan keys, return the subset that matches the given array key
void attachCols()
Attach the column objects and create unit keywor if needed.
ScalarColumn< String > & priority()
Definition: TableLogSink.h:244
Priority
An &quot;importance&quot; which is assigned to each LogMessage.
Definition: LogMessage.h:105
const ScalarColumn< Double > & roTime() const
Definition: TableLogSink.h:238
Distribute LogMessages to their destination(s)
Definition: LogSink.h:142
void reopenRW(const LogFilterInterface &filter)
Reopen the logtable for read/write (if needed).
String: the storage and methods of handling collections of characters.
Definition: String.h:225
static LogSink makeSink(const String &fileName)
Make a LogSink for a TableLogSink with a new table.
Definition: TableLogSink.h:259
MJD in seconds, UT.
Definition: TableLogSink.h:162
Define the structure of a Casacore table.
Definition: TableDesc.h:190
String id() const
Returns the id of the LogSink in use...
virtual void clearLocally()
Clear the local sink (i.e.
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.
const Bool True
Definition: aipstype.h:43
Informational log messages with with time, priority, and origin.
Definition: LogMessage.h:101
const ScalarColumn< String > & roPriority() const
Definition: TableLogSink.h:242
unsigned int uInt
Definition: aipstype.h:51
void makeTable(SetupNewTable &)
Make a new log table.
static String columnName(Columns which)
Turn the Columns enum into a String which is the actual column name in the Table. ...
Informational message.
Definition: TableLogSink.h:166