casa
$Rev:20696$
|
00001 //# StreamLogSink.h: Send log messages to an ostream. 00002 //# Copyright (C) 1996,2000,2001,2003 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id: StreamLogSink.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00028 00029 #ifndef CASA_STREAMLOGSINK_H 00030 #define CASA_STREAMLOGSINK_H 00031 00032 #include <casa/aips.h> 00033 #include <casa/Logging/LogSinkInterface.h> 00034 00035 #include <casa/iosfwd.h> 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 // <summary> 00040 // Send log messages to an ostream. 00041 // </summary> 00042 00043 // <use visibility=local> 00044 00045 // <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLogging.cc" demos="dLogging.cc"> 00046 // </reviewed> 00047 00048 // <prerequisite> 00049 // <li> <linkto class=LogSinkInterface>LogSinkInterface</linkto> 00050 // <li> ostream 00051 // </prerequisite> 00052 // 00053 // <etymology> 00054 // "Stream" from the family of standard C++ I/O classes. 00055 // </etymology> 00056 // 00057 // <synopsis> 00058 // <src>StreamLogSink</src> is a straightforward 00059 // <linkto class=LogSinkInterface>LogSinkInterface</linkto> which sends its 00060 // messages to an <src>ostream</src> (typically <src>cerr</src>) which it is 00061 // given at construction time. It is not intended to be used directly, rather it 00062 // should be used through <linkto class=LogSink>LogSink</linkto>. 00063 // </synopsis> 00064 // 00065 // <example> 00066 // See <linkto file="Logging.h">Logging.h</linkto>. 00067 // </example> 00068 // 00069 // <motivation> 00070 // Writing to standard output or error will be a common way of displaying log 00071 // messages. 00072 // </motivation> 00073 // 00074 // <todo asof="1996/07/24"> 00075 // <li> Nothing known. 00076 // </todo> 00077 00078 00079 00080 class StreamLogSink : public LogSinkInterface { 00081 public: 00082 // Defaults to <src>cerr</src> if no stream is supplied. The caller is 00083 // responsible for ensuring that the supplied <src>ostream</src> ostream 00084 // lives at least as long as this sink. If not filter is supplied, 00085 // <src>NORMAL</src> is used. 00086 // <group> 00087 explicit StreamLogSink(ostream *theStream = 0, bool deleteStream = false); 00088 explicit StreamLogSink(LogMessage::Priority filter, 00089 ostream *theStream = 0, bool deleteStream = false); 00090 explicit StreamLogSink(const LogFilterInterface &filter, 00091 ostream *theStream = 0, bool deleteStream = false); 00092 // </group> 00093 00094 // Make a copy of <src>other</src>. After copying, both objects will post 00095 // to the same stream. 00096 // <group> 00097 StreamLogSink(const StreamLogSink &other); 00098 StreamLogSink &operator=(const StreamLogSink &other); 00099 // </group> 00100 00101 ~StreamLogSink(); 00102 00103 // Write <src>message</src> to the stream if it passes the filter. Works 00104 // by calling <src>operator<<(ostream &,const LogMesssage&)</src>. 00105 virtual Bool postLocally(const LogMessage &message); 00106 00107 // write any pending output. 00108 virtual void flush (Bool global=True); 00109 00110 // Returns the id for this class... 00111 static String localId( ); 00112 // Returns the id of the LogSink in use... 00113 String id( ) const; 00114 00115 private: 00116 ostream *stream_p; 00117 bool deleteStream; 00118 }; 00119 00120 00121 } //# NAMESPACE CASA - END 00122 00123 #endif