casa  $Rev:20696$
TSLogSink.h
Go to the documentation of this file.
00001 //# TSLogSink.h: Save distributed log messages
00002 //# Copyright (C) 2005
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$
00028 
00029 #ifndef CASA_TSLOGSINK_H
00030 #define CASA_TSLOGSINK_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Logging/LogSink.h>
00035 #include <casa/Containers/Block.h>
00036 #include <casa/BasicSL/String.h>
00037 
00038 #include <fstream>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 //# Forward Declarations
00043 #ifndef AIPS_LOG4CPLUS
00044         class LogSinkInterface;
00045         class LogFilterInterface;
00046 #endif
00047 
00048 // <summary>
00049 // Save distributed log messages.
00050 // </summary>
00051 
00052 // <use visibility=export>
00053 
00054 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tLogging.cc" demos="dLogging.cc">
00055 // </reviewed>
00056 
00057 // <prerequisite>
00058 //   <li> <linkto class=LogSink>LogSink</linkto>
00059 // </prerequisite>
00060 //
00061 // <synopsis>
00062 // This class posts messages which pass the filter to 
00063 // a distributed logger.
00064 // </synopsis>
00065 //
00066 // <example>
00067 // See <linkto file="Logging.h">Logging.h</linkto>.
00068 // </example>
00069 //
00070 // <motivation>
00071 // For a distributed systems log messages.
00072 // </motivation>
00073 //
00074 //# <todo asof="2005/08/15">
00075 //# </todo>
00076 
00077 class TSLogSink : public LogSinkInterface
00078 {
00079 public:
00080   // Create an empty sink without a filter.
00081   TSLogSink();
00082 
00083   // Create an empty sink with the given filter.
00084   // <group>
00085   explicit TSLogSink (LogMessage::Priority filter);
00086   explicit TSLogSink (const LogFilterInterface& filter);
00087   // </group>
00088 
00089   // Copy constructor (copy semantics).
00090   TSLogSink (const TSLogSink& other);
00091 
00092   // Assignment (copy semantics).
00093   TSLogSink& operator= (const TSLogSink& other);
00094   
00095   virtual ~TSLogSink();
00096 
00097   // If the message passes the filter, write it
00098   virtual Bool postLocally (const LogMessage& message);
00099 
00100   // Returns the id for this class...
00101   static String localId( );
00102   // Returns the id of the LogSink in use...
00103   String id( ) const;
00104   const LogFilterInterface& filter() const;
00105   LogSinkInterface& filter(const LogFilterInterface &newfilter);
00106 #ifndef AIPSLOG4CPLUS
00107   void cerrToo(Bool);
00108   void setLogSink(String logname = "");
00109 #endif
00110 
00111 private:
00112   // Avoid duplicating code in copy ctor and assignment operator
00113   void copy_other (const TSLogSink& other);
00114 #ifndef AIPS_LOG4CPLUS
00115   LogSinkInterface *logsink;
00116   Bool send2cerr;
00117   std::ofstream *logfile;
00118 #endif
00119 
00120 };
00121 
00122 
00123 
00124 } //# NAMESPACE CASA - END
00125 
00126 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines