LogMessage.h

Classes

LogMessage -- Informational log messages with with time, priority, and origin. (full description)
Global Functions -- Write a LogMessage to an ostream. (full description)

class LogMessage

Types

enum Priority

DEBUGGING
Low priority - primarily used for findding problems or tracing execution.
NORMAL
Most messages users see should have this priority. Use for "interesting" informational messages from normally executing software.
WARN
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.
SEVERE
Report on a problem detected by the software. Messages logged at this priority will often be followed by a thrown exception.

Interface

Public Members
LogMessage(Priority priority=NORMAL)
LogMessage(const LogOrigin &sourceLocation, Priority priority=NORMAL)
LogMessage(const String &message, const LogOrigin &sourceLocation, Priority=NORMAL)
LogMessage(const LogMessage &other)
LogMessage &operator=(const LogMessage &other)
~LogMessage()
const String &message() const
LogMessage &message(const String &message, Bool keepLastTime = False)
uInt line() const
LogMessage &line(uInt which)
LogMessage &sourceLocation(const SourceLocation *where)
const LogOrigin &origin() const
LogMessage &origin(const LogOrigin &origin)
Priority priority() const
LogMessage &priority(Priority which)
const Time &messageTime() const
LogMessage &messageTime(const Time &theTime)
String toString() const
static const String &toString(Priority which)
Private Members
void copy_other(const LogMessage &other)

Description

Review Status

Reviewed By:
wbrouw
Date Reviewed:
1996/08/21
Programs:
Demos:
Tests:

Prerequisite

Synopsis

A LogMessage is the unit of information in the Logging system. A LogMessage consists of an informational text (String) message tagged with the following:

Example

    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.

To Do

Member Description

enum Priority

An "importance" which is assigned to each LogMessage.

LogMessage(Priority priority=NORMAL)

Create a message with the given priority and the current time, and an empty origin and message.

LogMessage(const LogOrigin &sourceLocation, 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 String &message, const LogOrigin &sourceLocation, Priority=NORMAL)

Create a completely filled out LogMessage.

LogMessage(const LogMessage &other)
LogMessage &operator=(const LogMessage &other)

Make this LogMessage a copy of other. Note that the time is also copied over.

~LogMessage()

const String &message() const

Get the message text.

LogMessage &message(const String &message, Bool keepLastTime = False)

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.

uInt line() const
LogMessage &line(uInt which)

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.

LogMessage &sourceLocation(const SourceLocation *where)

Set the source location - usually this will be called with the macro WHERE.

const LogOrigin &origin() const
LogMessage &origin(const LogOrigin &origin)

Get and set the origin of this LogMessage. If you only need the line number, use the line() or sourceOrigin() functions instead.

Priority priority() const
LogMessage &priority(Priority which)

Get or change the priority of this LogMessage.

const Time &messageTime() const

Returns the time at which the message text was created. This time is presently "computer operating system" precision time, not high-precision astronomical time.

LogMessage &messageTime(const Time &theTime)

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.

String toString() const

Turn this entire LogMessage into a String.

static const String &toString(Priority which)

Map the given priority into a String - so, for example, it can be stored in a table.

void copy_other(const LogMessage &other)

Provide common implementation for copy constructor and assignment operator


Write a LogMessage to an ostream. (source)

Interface

ostream &operator<<(ostream &os, const LogMessage &message)

Description

Write a LogMessage as a string to an ostream. Merely calls LogMessage::toString()

Member Description

ostream &operator<<(ostream &os, const LogMessage &message)