Loading...
Searching...
No Matches
TableLogSink.h
Go to the documentation of this file.
//# TableLogSink.h: Save log messages in a Casacore Table
//# Copyright (C) 1996,1997,1998,2000,2001,2003
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef TABLES_TABLELOGSINK_H
#define TABLES_TABLELOGSINK_H
//# Includes
#include <casacore/casa/aips.h>
#include <casacore/casa/Logging/LogSink.h>
#include <casacore/casa/Logging/LogFilter.h>
#include <casacore/tables/Tables/Table.h>
#include <casacore/tables/Tables/ScalarColumn.h>
#include <casacore/tables/Tables/ArrayColumn.h>
#include <casacore/casa/Utilities/Assert.h>
#include <casacore/casa/Exceptions/Error.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
//# Forward Declarations
class TableDesc;
class SetupNewTable;
// <summary>
// Save log messages in a Casacore Table
// </summary>
// <use visibility=export>
// <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLogging.cc" demos="dLogging.cc">
// </reviewed>
// <prerequisite>
// <li> <linkto class=LogSinkInterface>LogSinkInterface</linkto>
// <li> <linkto module=Tables>Tables</linkto>
// </prerequisite>
//
// <etymology>
// Log to a Casacore Table.
// </etymology>
//
// <synopsis>
// Unlike the other classes derived from
// <linkto class=LogSinkInterface>LogSinkInterface</linkto>, there are utility
// functions in this class which might be of some modest interest. In
// particular, the member functions which define the structure of the table
// and define the column names might be of interest.
//
// This class posts messages which pass the filter to a Casacore
// <linkto class=Table>Table</linkto>. It puts every field of the
// <linkto class=LogMessage>LogMessage</linkto> into its own column.
// </synopsis>
//
// <example>
// See <linkto file="Logging.h">Logging.h</linkto>.
// </example>
//
// <motivation>
// "Persistent" log messages must be stored in a Table.
// </motivation>
//
// <todo asof="2001/06/12">
// <li> Allow a subset of the columns to be written? e.g., only time,
// message, and priority.
// <li> Allow time sorting in concatenate?
// </todo>
class TableLogSink : public LogSinkInterface
{
public:
// If <src>fileName</src> exists, attach and append to it, otherwise create
// a table with that name. If the table exists, it must have all the
// required columns defined by <src>logTableDescription()</src>.
// <group>
TableLogSink (LogMessage::Priority filter, const String& fileName);
TableLogSink (const LogFilterInterface& filter, const String& fileName);
// </group>
// Open the log table for readonly.
// If needed, reopenRW can be used later to define a filter and
// to open the logtable for writing.
explicit TableLogSink (const String& fileName);
// After copying, both sinks will write to the same <src>Table</src>.
// <group>
TableLogSink (const TableLogSink& other);
TableLogSink& operator= (const TableLogSink& other);
// </group>
~TableLogSink();
// Reopen the logtable for read/write (if needed).
// When it actually reopens, the given filter will be used.
void reopenRW (const LogFilterInterface& filter);
// If the message passes the filter, write it to the log table.
virtual Bool postLocally (const LogMessage& message);
// Get number of messages in sink.
virtual uInt nelements() const;
// Get given part of the i-th message from the sink.
// <group>
virtual Double getTime (uInt i) const;
virtual String getPriority (uInt i) const;
virtual String getMessage (uInt i) const;
virtual String getLocation (uInt i) const;
virtual String getObjectID (uInt i) const;
// </group>
// Access to the actual log table and its columns.
// <note role=caution>
// Functions <src>time, priority, message, location, objectID</src>
// return a null <src>ScalarColumn</src> object when the logtable is
// not writable. Using it may result in using a null pointer
// causing a core dump. In debug mode it is checked if the object
// is not null.
// </note>
// <group>
const Table& table() const;
Table& table();
const ScalarColumn<Double>& roTime() const;
ScalarColumn<Double>& time();
const ScalarColumn<String>& roPriority() const;
ScalarColumn<String>& priority();
const ScalarColumn<String>& roMessage() const;
ScalarColumn<String>& message();
const ScalarColumn<String>& roLocation() const;
ScalarColumn<String>& location();
const ScalarColumn<String>& roObjectID() const;
ScalarColumn<String>& objectID();
// </group>
// Defines the minimal set of columns in the table (more may exist, but
// are ignored.
enum Columns {
// MJD in seconds, UT. (Double.)
TIME,
// Message importance. (String).
PRIORITY,
// Informational message. (String).
MESSAGE,
// Source code origin of the log message. Usually a combination of
// class name, method name, file name and line number, but any String
// is legal.
LOCATION,
// ObjectID of distributed object that created the message (String).
// If empty, no OBJECT_ID was set.
OBJECT_ID
};
// Turn the <src>Columns</src> enum into a String which is the actual
// column name in the <src>Table</src>.
static String columnName(Columns which);
// Description of the log table. You can use this if, e.g., you do not
// want to use the storage managers that this class creates by default
// (currently Miriad).
static TableDesc logTableDescription();
// Write out any pending output to the table.
virtual void flush (Bool global=True);
// Write a message (usually from another logsink) into the local one.
virtual void writeLocally (Double time, const String& message,
const String& priority, const String& location,
const String& objectID);
// Clear the local sink (i.e. remove all messages from it).
virtual void clearLocally();
// Returns the id for this class.
static String localId( );
// Returns the id of the LogSink in use.
String id( ) const;
// Make a LogSink for a TableLogSink with a new table.
// Default filter is <src>NORMAL</src>.
// <group>
static LogSink makeSink (const String& fileName);
static LogSink makeSink (LogMessage::Priority filter,
const String& fileName);
static LogSink makeSink (const LogFilterInterface& filter,
const String& fileName);
// </group>
private:
// Avoid duplicating code in copy ctor and assignment operator
void copy_other(const TableLogSink& other);
// Make a new log table.
void makeTable (SetupNewTable&);
// Attach the column objects and create unit keywor if needed.
void attachCols();
// Initialize the object.
void init (const String& fileName);
Table log_table_p;
ScalarColumn<Double> time_p;
ScalarColumn<String> priority_p;
ScalarColumn<String> message_p;
// Origin
ScalarColumn<String> location_p;
// ObjectID
ScalarColumn<String> id_p;
};
//# Inlines
inline const Table& TableLogSink::table() const {return log_table_p;}
inline Table& TableLogSink::table() {return log_table_p;}
inline const ScalarColumn<Double>& TableLogSink::roTime() const
{return time_p;}
inline ScalarColumn<Double>& TableLogSink::time()
{return time_p;}
inline const ScalarColumn<String>& TableLogSink::roPriority() const
{return priority_p;}
inline ScalarColumn<String>& TableLogSink::priority()
{return priority_p;}
inline const ScalarColumn<String>& TableLogSink::roLocation() const
{return location_p;}
inline ScalarColumn<String>& TableLogSink::location()
{return location_p;}
inline const ScalarColumn<String>& TableLogSink::roObjectID() const
{return id_p;}
inline ScalarColumn<String>& TableLogSink::objectID()
{return id_p;}
inline const ScalarColumn<String>& TableLogSink::roMessage() const
{return message_p;}
inline ScalarColumn<String>& TableLogSink::message()
{return message_p;}
inline LogSink TableLogSink::makeSink (const String& fileName)
{ return makeSink (LogFilter(), fileName); }
inline LogSink TableLogSink::makeSink (LogMessage::Priority filter,
const String& fileName)
{ return makeSink (LogFilter(filter), fileName); }
} //# NAMESPACE CASACORE - END
#endif
casacore::LogFilterInterface
Definition LogFilterInterface.h:82
casacore::LogFilter
Definition LogFilter.h:82
casacore::LogMessage
Definition LogMessage.h:98
casacore::LogMessage::Priority
Priority
An "importance" which is assigned to each LogMessage.
Definition LogMessage.h:102
casacore::LogSinkInterface::LogSinkInterface
LogSinkInterface()
Create with a NORMAL filter.
casacore::LogSinkInterface::filter
virtual const LogFilterInterface & filter() const
Get/set the filter.
casacore::LogSink
Definition LogSink.h:138
casacore::ScalarColumn
Definition ScalarColumn.h:83
casacore::SetupNewTable
Create a new table - define shapes, data managers, etc.
Definition SetupNewTab.h:337
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore::TableDesc
Definition TableDesc.h:189
casacore::TableLogSink::flush
virtual void flush(Bool global=True)
Write out any pending output to the table.
casacore::TableLogSink::TableLogSink
TableLogSink(LogMessage::Priority filter, const String &fileName)
If fileName exists, attach and append to it, otherwise create a table with that name.
casacore::TableLogSink::time_p
ScalarColumn< Double > time_p
Definition TableLogSink.h:220
casacore::TableLogSink::table
const Table & table() const
Access to the actual log table and its columns.
Definition TableLogSink.h:230
casacore::TableLogSink::roLocation
const ScalarColumn< String > & roLocation() const
Definition TableLogSink.h:241
casacore::TableLogSink::writeLocally
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.
casacore::TableLogSink::objectID
ScalarColumn< String > & objectID()
Definition TableLogSink.h:247
casacore::TableLogSink::operator=
TableLogSink & operator=(const TableLogSink &other)
casacore::TableLogSink::reopenRW
void reopenRW(const LogFilterInterface &filter)
Reopen the logtable for read/write (if needed).
casacore::TableLogSink::init
void init(const String &fileName)
Initialize the object.
casacore::TableLogSink::getMessage
virtual String getMessage(uInt i) const
casacore::TableLogSink::id_p
ScalarColumn< String > id_p
ObjectID.
Definition TableLogSink.h:226
casacore::TableLogSink::roObjectID
const ScalarColumn< String > & roObjectID() const
Definition TableLogSink.h:245
casacore::TableLogSink::TableLogSink
TableLogSink(const String &fileName)
Open the log table for readonly.
casacore::TableLogSink::logTableDescription
static TableDesc logTableDescription()
Description of the log table.
casacore::TableLogSink::TableLogSink
TableLogSink(const LogFilterInterface &filter, const String &fileName)
casacore::TableLogSink::columnName
static String columnName(Columns which)
Turn the Columns enum into a String which is the actual column name in the Table.
casacore::TableLogSink::priority
ScalarColumn< String > & priority()
Definition TableLogSink.h:239
casacore::TableLogSink::roTime
const ScalarColumn< Double > & roTime() const
Definition TableLogSink.h:233
casacore::TableLogSink::roMessage
const ScalarColumn< String > & roMessage() const
Definition TableLogSink.h:249
casacore::TableLogSink::message_p
ScalarColumn< String > message_p
Definition TableLogSink.h:222
casacore::TableLogSink::time
ScalarColumn< Double > & time()
Definition TableLogSink.h:235
casacore::TableLogSink::location_p
ScalarColumn< String > location_p
Origin.
Definition TableLogSink.h:224
casacore::TableLogSink::location
ScalarColumn< String > & location()
Definition TableLogSink.h:243
casacore::TableLogSink::postLocally
virtual Bool postLocally(const LogMessage &message)
If the message passes the filter, write it to the log table.
casacore::TableLogSink::TableLogSink
TableLogSink(const TableLogSink &other)
After copying, both sinks will write to the same Table.
casacore::TableLogSink::Columns
Columns
Defines the minimal set of columns in the table (more may exist, but are ignored.
Definition TableLogSink.h:157
casacore::TableLogSink::PRIORITY
@ PRIORITY
Message importance.
Definition TableLogSink.h:161
casacore::TableLogSink::OBJECT_ID
@ OBJECT_ID
ObjectID of distributed object that created the message (String).
Definition TableLogSink.h:170
casacore::TableLogSink::LOCATION
@ LOCATION
Source code origin of the log message.
Definition TableLogSink.h:167
casacore::TableLogSink::MESSAGE
@ MESSAGE
Informational message.
Definition TableLogSink.h:163
casacore::TableLogSink::TIME
@ TIME
MJD in seconds, UT.
Definition TableLogSink.h:159
casacore::TableLogSink::getLocation
virtual String getLocation(uInt i) const
casacore::TableLogSink::nelements
virtual uInt nelements() const
Get number of messages in sink.
casacore::TableLogSink::log_table_p
Table log_table_p
Definition TableLogSink.h:219
casacore::TableLogSink::getObjectID
virtual String getObjectID(uInt i) const
casacore::TableLogSink::makeSink
static LogSink makeSink(const LogFilterInterface &filter, const String &fileName)
casacore::TableLogSink::makeSink
static LogSink makeSink(const String &fileName)
Make a LogSink for a TableLogSink with a new table.
Definition TableLogSink.h:254
casacore::TableLogSink::priority_p
ScalarColumn< String > priority_p
Definition TableLogSink.h:221
casacore::TableLogSink::~TableLogSink
~TableLogSink()
casacore::TableLogSink::message
ScalarColumn< String > & message()
Definition TableLogSink.h:251
casacore::TableLogSink::localId
static String localId()
Returns the id for this class.
casacore::TableLogSink::getTime
virtual Double getTime(uInt i) const
Get given part of the i-th message from the sink.
casacore::TableLogSink::id
String id() const
Returns the id of the LogSink in use.
casacore::TableLogSink::attachCols
void attachCols()
Attach the column objects and create unit keywor if needed.
casacore::TableLogSink::copy_other
void copy_other(const TableLogSink &other)
Avoid duplicating code in copy ctor and assignment operator.
casacore::TableLogSink::roPriority
const ScalarColumn< String > & roPriority() const
Definition TableLogSink.h:237
casacore::TableLogSink::getPriority
virtual String getPriority(uInt i) const
casacore::TableLogSink::clearLocally
virtual void clearLocally()
Clear the local sink (i.e.
casacore::TableLogSink::makeTable
void makeTable(SetupNewTable &)
Make a new log table.
casacore::Table
Definition Table.h:157
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
casacore::True
const Bool True
Definition aipstype.h:41
casacore::Double
double Double
Definition aipstype.h:53