//# LogMessage.h: Informational log messages with with time,priority, and origin //# Copyright (C) 1996,1997,1999,2000,2001 //# Associated Universities, Inc. Washington DC, USA. //# //# This library is free software; you can redistribute it and/or modify it //# under the terms of the GNU Library General Public License as published by //# the Free Software Foundation; either version 2 of the License, or (at your //# option) any later version. //# //# This library is distributed in the hope that it will be useful, but WITHOUT //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public //# License for more details. //# //# You should have received a copy of the GNU Library General Public License //# along with this library; if not, write to the Free Software Foundation, //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning AIPS++ should be addressed as follows: //# Internet email: aips2-request@nrao.edu. //# Postal address: AIPS++ Project Office //# National Radio Astronomy Observatory //# 520 Edgemont Road //# Charlottesville, VA 22903-2475 USA //# //# //# $Id$ #ifndef CASA_LOGMESSAGE_H #define CASA_LOGMESSAGE_H #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN // // Informational log messages with with time, priority, and origin. // // // // // //
  • LogOrigin // // // // A LogMessage is the unit of information in the Logging system. // A LogMessage consists of an informational text (String) message tagged with // the following: //
      //
    • The time at which the message was generated ("computer" time, not high // precision astronomical time). //
    • A priority - one of DEBUGGING, NORMAL, // WARN, or SEVERE. //
    • A LogOrigin, containing the source // code location where the message originated. It also contains the // ObjectID if the originator was a // distributed object. This is mostly of use in debugging. //
    //
    // // // // void globalFunction(Int arg) // { // LogMessage logMessage(LogOrigin("globalFunction(Int arg)", WHERE)); // ... // logMessage.message("my message").line(__LINE__); // ... // logMessage.message("my second message").line(__LINE__); // ... // } // // void MyClass::member(Int arg) // { // LogMessage logMessage(LogOrigin("myClass", "member(Int arg)", WHERE)); // ... // logMessage.message("my message").line(__LINE__); // ... // } // // A more complete example is available in the module file // Logging.h. // // // //
  • Formerly we had a MessageType enum to go along with // Priority. It was removed because the categories weren't // sufficiently orthogonal. However the idea is probably sound and // we might eventually want to put such a categorization back. //
  • toRecord() and fromRecord() functions will be needed when we integrate // logging with Glish. // // class LogMessage { public: //# If you change this enum, edit toString() // An "importance" which is assigned to each LogMessage. enum Priority { // Low priority - primarily used for findding problems or tracing // execution. DEBUGGING, DEBUG2, DEBUG1, // Most messages users see should have this priority. Use for // "interesting" informational messages from normally executing // software. NORMAL5, NORMAL4, NORMAL3, NORMAL2, NORMAL1, NORMAL, // Use messages of warning level to flag things that are unusual and // might well be errors. Normally the software should proceed anyway // rather than throw an exception. WARN, // Report on a problem detected by the software. Messages logged at // this priority will often be followed by a thrown exception. SEVERE}; // Create a message with the given priority and the current time, and an // empty origin and message. LogMessage(Priority priority=NORMAL); // Create a message with the given location and priority, the current time // and an empty message. This will likely be the most commonly used // constructor when a given message is to be used several times in the same // function. LogMessage(const LogOrigin &sourceLocation, Priority priority=NORMAL); // Create a completely filled out LogMessage. LogMessage(const String &message, const LogOrigin &sourceLocation, Priority=NORMAL); // Make this LogMessage a copy of other. Note that // the time is also copied over. // LogMessage(const LogMessage &other); LogMessage &operator=(const LogMessage &other); // ~LogMessage(); // Get the message text. const String &message() const; // Set the message text. If keepLastTime is True, the // previous time will be used, otherwise the current time is used. This is // intended for messages that come out at essentially identical times to // aid in, e.g., Table selections. LogMessage &message(const String &message, Bool keepLastTime = False); // Get and set the line number in the // LogOrigin. While in principle you can // get and set this information through the origin() functions, // in practice it is convenient to be able to directly get at the line // number since it and the message text are usually the only things you // change in a particular LogMessage object. Generally you will set the // line number with the __LINE__ macro. // uInt line() const; LogMessage &line(uInt which); // // Set the source location - usually this will be called with the // macro WHERE. LogMessage &sourceLocation(const SourceLocation *where); // Get and set the origin of this LogMessage. If you only need the line // number, use the line() or sourceOrigin() // functions instead. // const LogOrigin &origin() const; LogMessage &origin(const LogOrigin &origin); // // Get or change the priority of this LogMessage. // Priority priority() const; LogMessage &priority(Priority which); // // Returns the time at which the message text was created. This time is // presently "computer operating system" precision time, not high-precision // astronomical time. const Time &messageTime() const; // Normally you should not manually set the time, however there may be // rare circumstances where it is useful - for example if you have a single // static message that you want to send out at various times. LogMessage &messageTime(const Time &theTime); // Turn this entire LogMessage into a String. String toString() const; String toTermString() const; // Map the given priority into a String - so, for example, it can be stored // in a table. static const String &toString(Priority which); private: String message_p; LogOrigin origin_p; Priority priority_p; Time time_p; // Provide common implementation for copy constructor and assignment // operator void copy_other(const LogMessage &other); }; // // Write a LogMessage to an ostream. // // Write a LogMessage as a string to an ostream. Merely calls // LogMessage::toString() // ostream &operator<<(ostream &os, const LogMessage &message); // } //# NAMESPACE CASACORE - END #endif