casa
$Rev:20696$
|
00001 //# LogMessage.h: Informational log messages with with time,priority, and origin 00002 //# Copyright (C) 1996,1997,1999,2000,2001 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: LogMessage.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00028 00029 #ifndef CASA_LOGMESSAGE_H 00030 #define CASA_LOGMESSAGE_H 00031 00032 #include <casa/aips.h> 00033 #include <casa/Logging/LogOrigin.h> 00034 #include <casa/OS/Time.h> 00035 #include <casa/iosfwd.h> 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 // <summary> 00040 // Informational log messages with with time, priority, and origin. 00041 //</summary> 00042 00043 // <use visibility=export> 00044 00045 // <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLoging.cc" demos="dLogging.cc"> 00046 // </reviewed> 00047 00048 // <prerequisite> 00049 // <li> <linkto class="LogOrigin">LogOrigin</linkto> 00050 // </prerequisite> 00051 // 00052 // <synopsis> 00053 // A <src>LogMessage</src> is the unit of information in the Logging system. 00054 // A LogMessage consists of an informational text (String) message tagged with 00055 // the following: 00056 // <ul> 00057 // <li> The time at which the message was generated ("computer" time, not high 00058 // precision astronomical time). 00059 // <li> A priority - one of <src>DEBUGGING</src>, <src>NORMAL</src>, 00060 // <src>WARN</src>, or <src>SEVERE</src>. 00061 // <li> A <linkto class="LogOrigin">LogOrigin</linkto>, containing the source 00062 // code location where the message originated. It also contains the 00063 // <linkto class="ObjectID">ObjectID</linkto> if the originator was a 00064 // distributed object. This is mostly of use in debugging. 00065 // </ul> 00066 // </synopsis> 00067 // 00068 // <example> 00069 // <srcblock> 00070 // void globalFunction(Int arg) 00071 // { 00072 // LogMessage logMessage(LogOrigin("globalFunction(Int arg)", WHERE)); 00073 // ... 00074 // logMessage.message("my message").line(__LINE__); 00075 // ... 00076 // logMessage.message("my second message").line(__LINE__); 00077 // ... 00078 // } 00079 // 00080 // void MyClass::member(Int arg) 00081 // { 00082 // LogMessage logMessage(LogOrigin("myClass", "member(Int arg)", WHERE)); 00083 // ... 00084 // logMessage.message("my message").line(__LINE__); 00085 // ... 00086 // } 00087 // </srcblock> 00088 // A more complete example is available in the module file 00089 // <linkto module="Logging">Logging.h</linkto>. 00090 // </example> 00091 // 00092 // <todo asof="1996/07/23"> 00093 // <li> Formerly we had a <src>MessageType</src> enum to go along with 00094 // <src>Priority</src>. It was removed because the categories weren't 00095 // sufficiently orthogonal. However the idea is probably sound and 00096 // we might eventually want to put such a categorization back. 00097 // <li> toRecord() and fromRecord() functions will be needed when we integrate 00098 // logging with Glish. 00099 // </todo> 00100 // 00101 class LogMessage { 00102 public: 00103 //# If you change this enum, edit toString() 00104 // An "importance" which is assigned to each LogMessage. 00105 enum Priority { 00106 // Low priority - primarily used for findding problems or tracing 00107 // execution. 00108 DEBUGGING, 00109 DEBUG2, 00110 DEBUG1, 00111 // Most messages users see should have this priority. Use for 00112 // "interesting" informational messages from normally executing 00113 // software. 00114 NORMAL5, 00115 NORMAL4, 00116 NORMAL3, 00117 NORMAL2, 00118 NORMAL1, 00119 NORMAL, 00120 // Use messages of warning level to flag things that are unusual and 00121 // might well be errors. Normally the software should proceed anyway 00122 // rather than throw an exception. 00123 WARN, 00124 // Report on a problem detected by the software. Messages logged at 00125 // this priority will often be followed by a thrown exception. 00126 SEVERE}; 00127 00128 // Create a message with the given priority and the current time, and an 00129 // empty origin and message. 00130 LogMessage(Priority priority=NORMAL); 00131 00132 // Create a message with the given location and priority, the current time 00133 // and an empty message. This will likely be the most commonly used 00134 // constructor when a given message is to be used several times in the same 00135 // function. 00136 LogMessage(const LogOrigin &sourceLocation, Priority priority=NORMAL); 00137 00138 // Create a completely filled out LogMessage. 00139 LogMessage(const String &message, const LogOrigin &sourceLocation, 00140 Priority=NORMAL); 00141 00142 // Make <src>this</src> LogMessage a copy of <src>other</src>. Note that 00143 // the time is also copied over. 00144 // <group> 00145 LogMessage(const LogMessage &other); 00146 LogMessage &operator=(const LogMessage &other); 00147 // </group> 00148 00149 ~LogMessage(); 00150 00151 // Get the message text. 00152 const String &message() const; 00153 00154 // Set the message text. If <src>keepLastTime</src> is <src>True</src>, the 00155 // previous time will be used, otherwise the current time is used. This is 00156 // intended for messages that come out at essentially identical times to 00157 // aid in, e.g., Table selections. 00158 LogMessage &message(const String &message, Bool keepLastTime = False); 00159 00160 // Get and set the line number in the 00161 // <linkto class="LogOrigin">LogOrigin</linkto>. While in principle you can 00162 // get and set this information through the <src>origin()</src> functions, 00163 // in practice it is convenient to be able to directly get at the line 00164 // number since it and the message text are usually the only things you 00165 // change in a particular LogMessage object. Generally you will set the 00166 // line number with the <src>__LINE__</src> macro. 00167 // <group> 00168 uInt line() const; 00169 LogMessage &line(uInt which); 00170 // </group> 00171 00172 // Set the source location - usually this will be called with the 00173 // macro WHERE. 00174 LogMessage &sourceLocation(const SourceLocation *where); 00175 00176 // Get and set the origin of this LogMessage. If you only need the line 00177 // number, use the <src>line()</src> or <src>sourceOrigin()</src> 00178 // functions instead. 00179 // <group> 00180 const LogOrigin &origin() const; 00181 LogMessage &origin(const LogOrigin &origin); 00182 // </group> 00183 00184 // Get or change the priority of this LogMessage. 00185 // <group> 00186 Priority priority() const; 00187 LogMessage &priority(Priority which); 00188 // </group> 00189 00190 // Returns the time at which the message text was created. This time is 00191 // presently "computer operating system" precision time, not high-precision 00192 // astronomical time. 00193 const Time &messageTime() const; 00194 00195 // Normally you should not manually set the time, however there may be 00196 // rare circumstances where it is useful - for example if you have a single 00197 // <src>static</src> message that you want to send out at various times. 00198 LogMessage &messageTime(const Time &theTime); 00199 00200 // Turn this entire LogMessage into a String. 00201 String toString() const; 00202 String toTermString() const; 00203 00204 // Map the given priority into a String - so, for example, it can be stored 00205 // in a table. 00206 static const String &toString(Priority which); 00207 private: 00208 String message_p; 00209 LogOrigin origin_p; 00210 Priority priority_p; 00211 Time time_p; 00212 00213 // Provide common implementation for copy constructor and assignment 00214 // operator 00215 void copy_other(const LogMessage &other); 00216 }; 00217 00218 // <summary> 00219 // Write a LogMessage to an ostream. 00220 // </summary> 00221 // Write a LogMessage as a string to an ostream. Merely calls 00222 // <src>LogMessage::toString()</src> 00223 // <group name=LogMessage_ostream> 00224 ostream &operator<<(ostream &os, const LogMessage &message); 00225 // </group> 00226 00227 00228 00229 } //# NAMESPACE CASA - END 00230 00231 #endif