casacore
Loading...
Searching...
No Matches
LogMessage.h
Go to the documentation of this file.
1//# LogMessage.h: Informational log messages with with time,priority, and origin
2//# Copyright (C) 1996,1997,1999,2000,2001
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: casa-feedback@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#ifndef CASA_LOGMESSAGE_H
27#define CASA_LOGMESSAGE_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Logging/LogOrigin.h>
31#include <casacore/casa/OS/Time.h>
32#include <casacore/casa/iosfwd.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Informational log messages with with time, priority, and origin.
38//</summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLoging.cc" demos="dLogging.cc">
43// </reviewed>
44
45// <prerequisite>
46// <li> <linkto class="LogOrigin">LogOrigin</linkto>
47// </prerequisite>
48//
49// <synopsis>
50// A <src>LogMessage</src> is the unit of information in the Logging system.
51// A LogMessage consists of an informational text (String) message tagged with
52// the following:
53// <ul>
54// <li> The time at which the message was generated ("computer" time, not high
55// precision astronomical time).
56// <li> A priority - one of <src>DEBUGGING</src>, <src>NORMAL</src>,
57// <src>WARN</src>, or <src>SEVERE</src>.
58// <li> A <linkto class="LogOrigin">LogOrigin</linkto>, containing the source
59// code location where the message originated. It also contains the
60// <linkto class="ObjectID">ObjectID</linkto> if the originator was a
61// distributed object. This is mostly of use in debugging.
62// </ul>
63// </synopsis>
64//
65// <example>
66// <srcblock>
67// void globalFunction(Int arg)
68// {
69// LogMessage logMessage(LogOrigin("globalFunction(Int arg)", WHERE));
70// ...
71// logMessage.message("my message").line(__LINE__);
72// ...
73// logMessage.message("my second message").line(__LINE__);
74// ...
75// }
76//
77// void MyClass::member(Int arg)
78// {
79// LogMessage logMessage(LogOrigin("myClass", "member(Int arg)", WHERE));
80// ...
81// logMessage.message("my message").line(__LINE__);
82// ...
83// }
84// </srcblock>
85// A more complete example is available in the module file
86// <linkto module="Logging">Logging.h</linkto>.
87// </example>
88//
89// <todo asof="1996/07/23">
90// <li> Formerly we had a <src>MessageType</src> enum to go along with
91// <src>Priority</src>. It was removed because the categories weren't
92// sufficiently orthogonal. However the idea is probably sound and
93// we might eventually want to put such a categorization back.
94// <li> toRecord() and fromRecord() functions will be needed when we integrate
95// logging with Glish.
96// </todo>
97//
99public:
100 //# If you change this enum, edit toString()
101 // An "importance" which is assigned to each LogMessage.
102 enum Priority {
103 // Low priority - primarily used for findding problems or tracing
104 // execution.
108 // Most messages users see should have this priority. Use for
109 // "interesting" informational messages from normally executing
110 // software.
117 // Use messages of warning level to flag things that are unusual and
118 // might well be errors. Normally the software should proceed anyway
119 // rather than throw an exception.
121 // Report on a problem detected by the software. Messages logged at
122 // this priority will often be followed by a thrown exception.
124
125 // Create a message with the given priority and the current time, and an
126 // empty origin and message.
128
129 // Create a message with the given location and priority, the current time
130 // and an empty message. This will likely be the most commonly used
131 // constructor when a given message is to be used several times in the same
132 // function.
134
135 // Create a completely filled out LogMessage.
138
139 // Make <src>this</src> LogMessage a copy of <src>other</src>. Note that
140 // the time is also copied over.
141 // <group>
142 LogMessage(const LogMessage &other);
144 // </group>
145
147
148 // Get the message text.
149 const String &message() const;
150
151 // Set the message text. If <src>keepLastTime</src> is <src>True</src>, the
152 // previous time will be used, otherwise the current time is used. This is
153 // intended for messages that come out at essentially identical times to
154 // aid in, e.g., Table selections.
155 LogMessage &message(const String &message, Bool keepLastTime = False);
156
157 // Get and set the line number in the
158 // <linkto class="LogOrigin">LogOrigin</linkto>. While in principle you can
159 // get and set this information through the <src>origin()</src> functions,
160 // in practice it is convenient to be able to directly get at the line
161 // number since it and the message text are usually the only things you
162 // change in a particular LogMessage object. Generally you will set the
163 // line number with the <src>__LINE__</src> macro.
164 // <group>
165 uInt line() const;
167 // </group>
168
169 // Set the source location - usually this will be called with the
170 // macro WHERE.
171 LogMessage &sourceLocation(const SourceLocation *where);
172
173 // Get and set the origin of this LogMessage. If you only need the line
174 // number, use the <src>line()</src> or <src>sourceOrigin()</src>
175 // functions instead.
176 // <group>
177 const LogOrigin &origin() const;
179 // </group>
180
181 // Get or change the priority of this LogMessage.
182 // <group>
185 // </group>
186
187 // Returns the time at which the message text was created. This time is
188 // presently "computer operating system" precision time, not high-precision
189 // astronomical time.
190 const Time &messageTime() const;
191
192 // Normally you should not manually set the time, however there may be
193 // rare circumstances where it is useful - for example if you have a single
194 // <src>static</src> message that you want to send out at various times.
195 LogMessage &messageTime(const Time &theTime);
196
197 // Turn this entire LogMessage into a String.
200
201 // Map the given priority into a String - so, for example, it can be stored
202 // in a table.
203 static const String &toString(Priority which);
204private:
209
210 // Provide common implementation for copy constructor and assignment
211 // operator
212 void copy_other(const LogMessage &other);
213};
214
215// <summary>
216// Write a LogMessage to an ostream.
217// </summary>
218// Write a LogMessage as a string to an ostream. Merely calls
219// <src>LogMessage::toString()</src>
220// <group name=LogMessage_ostream>
221ostream &operator<<(ostream &os, const LogMessage &message);
222// </group>
223
224
225
226} //# NAMESPACE CASACORE - END
227
228#endif
LogMessage & sourceLocation(const SourceLocation *where)
Set the source location - usually this will be called with the macro WHERE.
LogMessage(const LogMessage &other)
Make this LogMessage a copy of other.
LogMessage(const String &message, const LogOrigin &sourceLocation, Priority=NORMAL)
Create a completely filled out LogMessage.
LogMessage & priority(Priority which)
LogMessage & message(const String &message, Bool keepLastTime=False)
Set the message text.
const String & message() const
Get the message text.
static const String & toString(Priority which)
Map the given priority into a String - so, for example, it can be stored in a table.
String toString() const
Turn this entire LogMessage into a String.
const LogOrigin & origin() const
Get and set the origin of this LogMessage.
Priority
An "importance" which is assigned to each LogMessage.
Definition LogMessage.h:102
@ WARN
Use messages of warning level to flag things that are unusual and might well be errors.
Definition LogMessage.h:120
@ DEBUGGING
Low priority - primarily used for findding problems or tracing execution.
Definition LogMessage.h:105
@ NORMAL5
Most messages users see should have this priority.
Definition LogMessage.h:111
@ SEVERE
Report on a problem detected by the software.
Definition LogMessage.h:123
uInt line() const
Get and set the line number in the LogOrigin.
LogMessage & origin(const LogOrigin &origin)
String toTermString() const
LogMessage(Priority priority=NORMAL)
Create a message with the given priority and the current time, and an empty origin and message.
LogMessage & line(uInt which)
void copy_other(const LogMessage &other)
Provide common implementation for copy constructor and assignment operator.
LogMessage & messageTime(const Time &theTime)
Normally you should not manually set the time, however there may be rare circumstances where it is us...
const Time & messageTime() const
Returns the time at which the message text was created.
LogMessage(const LogOrigin &sourceLocation, Priority priority=NORMAL)
Create a message with the given location and priority, the current time and an empty message.
LogMessage & operator=(const LogMessage &other)
Priority priority() const
Get or change the priority of this LogMessage.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
ostream & operator<<(ostream &os, const LogMessage &message)