casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StreamLogSink.h
Go to the documentation of this file.
1 //# StreamLogSink.h: Send log messages to an ostream.
2 //# Copyright (C) 1996,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 CASA_STREAMLOGSINK_H
30 #define CASA_STREAMLOGSINK_H
31 
32 #include <casacore/casa/aips.h>
34 
35 #include <casacore/casa/iosfwd.h>
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 // <summary>
40 // Send log messages to an ostream.
41 // </summary>
42 
43 // <use visibility=local>
44 
45 // <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLogging.cc" demos="dLogging.cc">
46 // </reviewed>
47 
48 // <prerequisite>
49 // <li> <linkto class=LogSinkInterface>LogSinkInterface</linkto>
50 // <li> ostream
51 // </prerequisite>
52 //
53 // <etymology>
54 // "Stream" from the family of standard C++ I/O classes.
55 // </etymology>
56 //
57 // <synopsis>
58 // <src>StreamLogSink</src> is a straightforward
59 // <linkto class=LogSinkInterface>LogSinkInterface</linkto> which sends its
60 // messages to an <src>ostream</src> (typically <src>cerr</src>) which it is
61 // given at construction time. It is not intended to be used directly, rather it
62 // should be used through <linkto class=LogSink>LogSink</linkto>.
63 // </synopsis>
64 //
65 // <example>
66 // See <linkto file="Logging.h">Logging.h</linkto>.
67 // </example>
68 //
69 // <motivation>
70 // Writing to standard output or error will be a common way of displaying log
71 // messages.
72 // </motivation>
73 //
74 // <todo asof="1996/07/24">
75 // <li> Nothing known.
76 // </todo>
77 
78 
79 
81 public:
82  // Defaults to <src>cerr</src> if no stream is supplied. The caller is
83  // responsible for ensuring that the supplied <src>ostream</src> ostream
84  // lives at least as long as this sink. If not filter is supplied,
85  // <src>NORMAL</src> is used.
86  // <group>
87  explicit StreamLogSink(ostream *theStream = 0, bool deleteStream = false);
89  ostream *theStream = 0, bool deleteStream = false);
90  explicit StreamLogSink(const LogFilterInterface &filter,
91  ostream *theStream = 0, bool deleteStream = false);
92  // </group>
93 
94  // Make a copy of <src>other</src>. After copying, both objects will post
95  // to the same stream.
96  // <group>
97  StreamLogSink(const StreamLogSink &other);
98  StreamLogSink &operator=(const StreamLogSink &other);
99  // </group>
100 
101  ~StreamLogSink();
102 
103  // Write <src>message</src> to the stream if it passes the filter. Works
104  // by calling <src>operator<<(ostream &,const LogMesssage&)</src>.
105  virtual Bool postLocally(const LogMessage &message);
106 
107  // write any pending output.
108  virtual void flush (Bool global=True);
109 
110  // Returns the id for this class...
111  static String localId( );
112  // Returns the id of the LogSink in use...
113  String id( ) const;
114 
115 private:
116  ostream *stream_p;
118 };
119 
120 
121 } //# NAMESPACE CASACORE - END
122 
123 #endif
String id() const
Returns the id of the LogSink in use...
Send log messages to an ostream.
Definition: StreamLogSink.h:80
Abstract base class for filtering LogMessages.
virtual void flush(Bool global=True)
write any pending output.
StreamLogSink(ostream *theStream=0, bool deleteStream=false)
Defaults to cerr if no stream is supplied.
Accepts LogMessages and posts them to some destination.
static String localId()
Returns the id for this class...
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual const LogFilterInterface & filter() const
Get/set the filter.
Priority
An &quot;importance&quot; which is assigned to each LogMessage.
Definition: LogMessage.h:105
virtual Bool postLocally(const LogMessage &message)
Write message to the stream if it passes the filter.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
StreamLogSink & operator=(const StreamLogSink &other)
const Bool True
Definition: aipstype.h:43
Informational log messages with with time, priority, and origin.
Definition: LogMessage.h:101