ROSE  0.9.10.103
Public Member Functions | List of all members
Sawyer::Message::Facility Class Reference

Description

Collection of streams.

This forms a collection of message streams for a software component and contains one stream per message importance level. A facility is intended to be used by a software component at whatever granularity is desired by the author (program, name space, class, method, etc.) and is usually given a string name that is related to the software component which it serves. The string name becomes part of messages and is also the default name used by Facilities::control. All message streams created for the facility are given the same name, message prefix generator, and message sink, but they can be adjusted later on a per-stream basis.

The C++ name for the facility is often just "mlog" or "logger" (appropriately scoped) so that code to emit messages is self documenting. The name "log" is sometimes used, but can be ambiguous with the ::log function in math.h.

mlog[ERROR] <<"I got an error\n";

Thread safety: This object is thread-safe except where noted.

Definition at line 1579 of file Message.h.

#include <Message.h>

Public Member Functions

 Facility ()
 Construct an empty facility. More...
 
 Facility (const Facility &other)
 Construct a new facility from an existing facility. More...
 
Facilityoperator= (const Facility &src)
 Assignment operator. More...
 
 Facility (const std::string &name)
 Create a named facility with default destinations. More...
 
 Facility (const std::string &name, const DestinationPtr &destination)
 Creates streams of all importance levels. More...
 
bool isConstructed () const
 Returns true if called on an object that has been constructed. More...
 
std::string name () const
 Return the name of the facility. More...
 
FacilityrenameStreams (const std::string &name="")
 Renames all the facility streams. More...
 
FacilityinitStreams (const DestinationPtr &)
 Cause all streams to use the specified destination. More...
 
Streamget (Importance imp)
 Returns a stream for the specified importance level. More...
 
Streamoperator[] (Importance imp)
 Returns a stream for the specified importance level. More...
 
std::string comment () const
 Property: Comment associated with facility. More...
 
Facilitycomment (const std::string &)
 Property: Comment associated with facility. More...
 

Constructor & Destructor Documentation

Sawyer::Message::Facility::Facility ( )
inline

Construct an empty facility.

The facility will have no name and all streams will be uninitialized. Any attempt to emit anything to a facility in the default state will cause an std::runtime_error to be thrown with a message similar to "stream INFO is not initialized yet". This facility can be initialized by assigning it a value from another initialized facility.

Definition at line 1594 of file Message.h.

Sawyer::Message::Facility::Facility ( const Facility other)

Construct a new facility from an existing facility.

The new facility will point to the same streams as the existing facility.

Sawyer::Message::Facility::Facility ( const std::string &  name)
inlineexplicit

Create a named facility with default destinations.

All streams are enabled and all output goes to file descriptor 2 (standard error) via unbuffered system calls. Facilities initialized to this state can typically be used before the C++ runtime is fully initialized and before Sawyer::initializeLibrary is called.

Definition at line 1609 of file Message.h.

References Sawyer::Message::FdSink::instance().

Sawyer::Message::Facility::Facility ( const std::string &  name,
const DestinationPtr destination 
)
inline

Creates streams of all importance levels.

Definition at line 1615 of file Message.h.

Member Function Documentation

Facility& Sawyer::Message::Facility::operator= ( const Facility src)

Assignment operator.

The destination facility will point to the same streams as the source facility.

bool Sawyer::Message::Facility::isConstructed ( ) const
inline

Returns true if called on an object that has been constructed.

Returns true if this is constructed, false if it's allocated but not constructed. For instance, this method may return false if the object is declared at namespace scope and this method is called before the C++ runtime has had a chance to initialize it.

Thread safety: This method is not thread-safe.

Definition at line 1630 of file Message.h.

Stream& Sawyer::Message::Facility::get ( Importance  imp)

Returns a stream for the specified importance level.

It is permissible to do the following:

Stream m1 = (mlog[INFO] <<"message 1 part 1");
Stream m2 = (mlog[INFO] <<"message 2 part 1");
m1 <<" part 2\n";
m2 <<" part 2\n";

Thread safety: This method is thread-safe.

Stream& Sawyer::Message::Facility::operator[] ( Importance  imp)
inline

Returns a stream for the specified importance level.

It is permissible to do the following:

Stream m1 = (mlog[INFO] <<"message 1 part 1");
Stream m2 = (mlog[INFO] <<"message 2 part 1");
m1 <<" part 2\n";
m2 <<" part 2\n";

Thread safety: This method is thread-safe.

Definition at line 1647 of file Message.h.

std::string Sawyer::Message::Facility::name ( ) const

Return the name of the facility.

This is a read-only field initialized at construction time.

Thread safety: This method is thread-safe.

std::string Sawyer::Message::Facility::comment ( ) const

Property: Comment associated with facility.

The comment should be a single-line string without terminating punctuation (for consistency, although not enforced). The comment is printed as part of the output when listing the facility names.

Thread safety: This method is thread-safe.

Facility& Sawyer::Message::Facility::comment ( const std::string &  )

Property: Comment associated with facility.

The comment should be a single-line string without terminating punctuation (for consistency, although not enforced). The comment is printed as part of the output when listing the facility names.

Thread safety: This method is thread-safe.

Facility& Sawyer::Message::Facility::renameStreams ( const std::string &  name = "")

Renames all the facility streams.

Invokes Stream::facilityName for each stream. If a name is given then that name is used, otherwise this facility's name is used.

Thread safety: This method is thread-safe.

Facility& Sawyer::Message::Facility::initStreams ( const DestinationPtr )

Cause all streams to use the specified destination.

This can be called for facilities that already have streams and destinations, but it can also be called to initialize the streams for a default-constructed facility.

Thread safety: This method is thread-safe.


The documentation for this class was generated from the following file: