casacore
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>
34#include <casacore/casa/Logging/LogSink.h>
35#include <casacore/casa/Logging/LogFilter.h>
36#include <casacore/tables/Tables/Table.h>
37#include <casacore/tables/Tables/ScalarColumn.h>
38#include <casacore/tables/Tables/ArrayColumn.h>
39#include <casacore/casa/Utilities/Assert.h>
40#include <casacore/casa/Exceptions/Error.h>
41
42namespace casacore { //# NAMESPACE CASACORE - BEGIN
43
44//# Forward Declarations
45class TableDesc;
46class 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{
94public:
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>
112 // </group>
113
115
116 // Reopen the logtable for read/write (if needed).
117 // When it actually reopens, the given filter will be used.
119
120 // If the message passes the filter, write it to the log table.
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);
206 const String& fileName);
208 const String& fileName);
209 // </group>
210
211private:
212 // Undefined and inaccessible
214 // Avoid duplicating code in copy ctor and assignment operator
215 void copy_other(const TableLogSink& other);
216 // Make a new log table.
218 // Attach the column objects and create unit keywor if needed.
220 // Initialize the object.
221 void init (const String& fileName);
222
223
228 // Origin
230 // ObjectID
232};
233
234//# Inlines
235inline 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
259inline 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
Priority
An "importance" which is assigned to each LogMessage.
Definition: LogMessage.h:105
virtual const LogFilterInterface & filter() const
Get/set the filter.
Create a new table - define shapes, data managers, etc.
Definition: SetupNewTab.h:341
String: the storage and methods of handling collections of characters.
Definition: String.h:225
virtual void flush(Bool global=True)
Write out any pending output to the table.
TableLogSink(LogMessage::Priority filter, const String &fileName)
If fileName exists, attach and append to it, otherwise create a table with that name.
ScalarColumn< Double > time_p
Definition: TableLogSink.h:225
const Table & table() const
Access to the actual log table and its columns.
Definition: TableLogSink.h:235
const ScalarColumn< String > & roLocation() const
Definition: TableLogSink.h:246
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.
ScalarColumn< String > & objectID()
Definition: TableLogSink.h:252
TableLogSink & operator=(const TableLogSink &other)
void reopenRW(const LogFilterInterface &filter)
Reopen the logtable for read/write (if needed).
void init(const String &fileName)
Initialize the object.
virtual String getMessage(uInt i) const
ScalarColumn< String > id_p
ObjectID.
Definition: TableLogSink.h:231
const ScalarColumn< String > & roObjectID() const
Definition: TableLogSink.h:250
TableLogSink(const String &fileName)
Open the log table for readonly.
static TableDesc logTableDescription()
Description of the log table.
TableLogSink()
Undefined and inaccessible.
TableLogSink(const LogFilterInterface &filter, const String &fileName)
static String columnName(Columns which)
Turn the Columns enum into a String which is the actual column name in the Table.
ScalarColumn< String > & priority()
Definition: TableLogSink.h:244
const ScalarColumn< Double > & roTime() const
Definition: TableLogSink.h:238
const ScalarColumn< String > & roMessage() const
Definition: TableLogSink.h:254
ScalarColumn< String > message_p
Definition: TableLogSink.h:227
ScalarColumn< Double > & time()
Definition: TableLogSink.h:240
ScalarColumn< String > location_p
Origin.
Definition: TableLogSink.h:229
ScalarColumn< String > & location()
Definition: TableLogSink.h:248
virtual Bool postLocally(const LogMessage &message)
If the message passes the filter, write it to the log table.
TableLogSink(const TableLogSink &other)
After copying, both sinks will write to the same Table.
Columns
Defines the minimal set of columns in the table (more may exist, but are ignored.
Definition: TableLogSink.h:160
@ PRIORITY
Message importance.
Definition: TableLogSink.h:164
@ OBJECT_ID
ObjectID of distributed object that created the message (String).
Definition: TableLogSink.h:173
@ LOCATION
Source code origin of the log message.
Definition: TableLogSink.h:170
@ MESSAGE
Informational message.
Definition: TableLogSink.h:166
@ TIME
MJD in seconds, UT.
Definition: TableLogSink.h:162
virtual String getLocation(uInt i) const
virtual uInt nelements() const
Get number of messages in sink.
virtual String getObjectID(uInt i) const
static LogSink makeSink(const LogFilterInterface &filter, const String &fileName)
static LogSink makeSink(const String &fileName)
Make a LogSink for a TableLogSink with a new table.
Definition: TableLogSink.h:259
ScalarColumn< String > priority_p
Definition: TableLogSink.h:226
ScalarColumn< String > & message()
Definition: TableLogSink.h:256
static String localId()
Returns the id for this class...
virtual Double getTime(uInt i) const
Get given part of the i-th message from the sink.
String id() const
Returns the id of the LogSink in use...
void attachCols()
Attach the column objects and create unit keywor if needed.
void copy_other(const TableLogSink &other)
Avoid duplicating code in copy ctor and assignment operator.
const ScalarColumn< String > & roPriority() const
Definition: TableLogSink.h:242
virtual String getPriority(uInt i) const
virtual void clearLocally()
Clear the local sink (i.e.
void makeTable(SetupNewTable &)
Make a new log table.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
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
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43
double Double
Definition: aipstype.h:55