casacore
Loading...
Searching...
No Matches
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: 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 TABLES_TABLELOGSINK_H
27#define TABLES_TABLELOGSINK_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Logging/LogSink.h>
32#include <casacore/casa/Logging/LogFilter.h>
33#include <casacore/tables/Tables/Table.h>
34#include <casacore/tables/Tables/ScalarColumn.h>
35#include <casacore/tables/Tables/ArrayColumn.h>
36#include <casacore/casa/Utilities/Assert.h>
37#include <casacore/casa/Exceptions/Error.h>
38
39namespace casacore { //# NAMESPACE CASACORE - BEGIN
40
41//# Forward Declarations
42class TableDesc;
43class SetupNewTable;
44
45// <summary>
46// Save log messages in a Casacore Table
47// </summary>
48
49// <use visibility=export>
50
51// <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLogging.cc" demos="dLogging.cc">
52// </reviewed>
53
54// <prerequisite>
55// <li> <linkto class=LogSinkInterface>LogSinkInterface</linkto>
56// <li> <linkto module=Tables>Tables</linkto>
57// </prerequisite>
58//
59// <etymology>
60// Log to a Casacore Table.
61// </etymology>
62//
63// <synopsis>
64// Unlike the other classes derived from
65// <linkto class=LogSinkInterface>LogSinkInterface</linkto>, there are utility
66// functions in this class which might be of some modest interest. In
67// particular, the member functions which define the structure of the table
68// and define the column names might be of interest.
69//
70// This class posts messages which pass the filter to a Casacore
71// <linkto class=Table>Table</linkto>. It puts every field of the
72// <linkto class=LogMessage>LogMessage</linkto> into its own column.
73// </synopsis>
74//
75// <example>
76// See <linkto file="Logging.h">Logging.h</linkto>.
77// </example>
78//
79// <motivation>
80// "Persistent" log messages must be stored in a Table.
81// </motivation>
82//
83// <todo asof="2001/06/12">
84// <li> Allow a subset of the columns to be written? e.g., only time,
85// message, and priority.
86// <li> Allow time sorting in concatenate?
87// </todo>
88
90{
91public:
92 // If <src>fileName</src> exists, attach and append to it, otherwise create
93 // a table with that name. If the table exists, it must have all the
94 // required columns defined by <src>logTableDescription()</src>.
95 // <group>
97 TableLogSink (const LogFilterInterface& filter, const String& fileName);
98 // </group>
99
100 // Open the log table for readonly.
101 // If needed, reopenRW can be used later to define a filter and
102 // to open the logtable for writing.
103 explicit TableLogSink (const String& fileName);
104
105 // After copying, both sinks will write to the same <src>Table</src>.
106 // <group>
109 // </group>
110
112
113 // Reopen the logtable for read/write (if needed).
114 // When it actually reopens, the given filter will be used.
116
117 // If the message passes the filter, write it to the log table.
119
120 // Get number of messages in sink.
121 virtual uInt nelements() const;
122
123 // Get given part of the i-th message from the sink.
124 // <group>
125 virtual Double getTime (uInt i) const;
126 virtual String getPriority (uInt i) const;
127 virtual String getMessage (uInt i) const;
128 virtual String getLocation (uInt i) const;
129 virtual String getObjectID (uInt i) const;
130 // </group>
131
132 // Access to the actual log table and its columns.
133 // <note role=caution>
134 // Functions <src>time, priority, message, location, objectID</src>
135 // return a null <src>ScalarColumn</src> object when the logtable is
136 // not writable. Using it may result in using a null pointer
137 // causing a core dump. In debug mode it is checked if the object
138 // is not null.
139 // </note>
140 // <group>
141 const Table& table() const;
142 Table& table();
143 const ScalarColumn<Double>& roTime() const;
145 const ScalarColumn<String>& roPriority() const;
147 const ScalarColumn<String>& roMessage() const;
149 const ScalarColumn<String>& roLocation() const;
151 const ScalarColumn<String>& roObjectID() const;
153 // </group>
154
155 // Defines the minimal set of columns in the table (more may exist, but
156 // are ignored.
157 enum Columns {
158 // MJD in seconds, UT. (Double.)
160 // Message importance. (String).
162 // Informational message. (String).
164 // Source code origin of the log message. Usually a combination of
165 // class name, method name, file name and line number, but any String
166 // is legal.
168 // ObjectID of distributed object that created the message (String).
169 // If empty, no OBJECT_ID was set.
171 };
172
173 // Turn the <src>Columns</src> enum into a String which is the actual
174 // column name in the <src>Table</src>.
175 static String columnName(Columns which);
176
177 // Description of the log table. You can use this if, e.g., you do not
178 // want to use the storage managers that this class creates by default
179 // (currently Miriad).
181
182 // Write out any pending output to the table.
183 virtual void flush (Bool global=True);
184
185 // Write a message (usually from another logsink) into the local one.
186 virtual void writeLocally (Double time, const String& message,
187 const String& priority, const String& location,
188 const String& objectID);
189
190 // Clear the local sink (i.e. remove all messages from it).
191 virtual void clearLocally();
192
193 // Returns the id for this class.
194 static String localId( );
195 // Returns the id of the LogSink in use.
196 String id( ) const;
197
198 // Make a LogSink for a TableLogSink with a new table.
199 // Default filter is <src>NORMAL</src>.
200 // <group>
201 static LogSink makeSink (const String& fileName);
203 const String& fileName);
205 const String& fileName);
206 // </group>
207
208private:
209 // Avoid duplicating code in copy ctor and assignment operator
210 void copy_other(const TableLogSink& other);
211 // Make a new log table.
213 // Attach the column objects and create unit keywor if needed.
215 // Initialize the object.
216 void init (const String& fileName);
217
218
223 // Origin
225 // ObjectID
227};
228
229//# Inlines
230inline const Table& TableLogSink::table() const {return log_table_p;}
232
234 {return time_p;}
238 {return priority_p;}
242 {return location_p;}
246 {return id_p;}
250 {return message_p;}
253
254inline LogSink TableLogSink::makeSink (const String& fileName)
255 { return makeSink (LogFilter(), fileName); }
257 const String& fileName)
258 { return makeSink (LogFilter(filter), fileName); }
259
260
261
262} //# NAMESPACE CASACORE - END
263
264#endif
Priority
An "importance" which is assigned to each LogMessage.
Definition LogMessage.h:102
virtual const LogFilterInterface & filter() const
Get/set the filter.
Create a new table - define shapes, data managers, etc.
String: the storage and methods of handling collections of characters.
Definition String.h:223
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
const Table & table() const
Access to the actual log table and its columns.
const ScalarColumn< String > & roLocation() const
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()
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.
const ScalarColumn< String > & roObjectID() const
TableLogSink(const String &fileName)
Open the log table for readonly.
static TableDesc logTableDescription()
Description of the log table.
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()
const ScalarColumn< Double > & roTime() const
const ScalarColumn< String > & roMessage() const
ScalarColumn< String > message_p
ScalarColumn< Double > & time()
ScalarColumn< String > location_p
Origin.
ScalarColumn< String > & location()
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.
@ PRIORITY
Message importance.
@ OBJECT_ID
ObjectID of distributed object that created the message (String).
@ LOCATION
Source code origin of the log message.
@ MESSAGE
Informational message.
@ TIME
MJD in seconds, UT.
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.
ScalarColumn< String > priority_p
ScalarColumn< String > & message()
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
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:49
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:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53