ROSE
0.11.96.11
|
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. The name follows a particular syntax described below. 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.
The string name for the facility follows a particular syntax: the name is composed of one or more components separated from one another by separators. Each component contains one or more letters, digits, and underscores. A separator is a dot ("."), one or two colons (":" or "::"), or a hyphen ("-").
Thread safety: This object is thread-safe except where noted.
#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... | |
Facility & | operator= (const Facility &src) |
Assignment operator. More... | |
Facility (const std::string &name, const DestinationPtr &destination) | |
Facility & | initialize (const std::string &name) |
Initializes this facility with default destinations. More... | |
Facility & | initialize (const std::string &name, const DestinationPtr &destination) |
Initialize all streams with specified destination. | |
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... | |
Facility & | renameStreams (const std::string &name="") |
Renames all the facility streams. More... | |
Facility & | initStreams (const DestinationPtr &) |
Cause all streams to use the specified destination. More... | |
Stream & | get (Importance imp) |
Returns a stream for the specified importance level. More... | |
Stream & | operator[] (Importance imp) |
Returns a stream for the specified importance level. More... | |
std::string | comment () const |
Property: Comment associated with facility. More... | |
Facility & | comment (const std::string &) |
Property: Comment associated with facility. More... | |
Static Public Member Functions | |
static bool | isValidName (const std::string &) |
Tests whether a name is valie. More... | |
Static Protected Member Functions | |
static std::vector< std::string > | parseName (const std::string &) |
|
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.
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.
Assignment operator.
The destination facility will point to the same streams as the source facility.
Facility& Sawyer::Message::Facility::initialize | ( | const std::string & | name | ) |
Initializes this facility with default destinations.
All streams are enabled and all output goes to file descriptor 2 (standard error) via unbuffered system calls.
|
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.
Stream& Sawyer::Message::Facility::get | ( | Importance | imp | ) |
|
inline |
Returns a stream for the specified importance level.
It is permissible to do the following:
Thread safety: This method is thread-safe.
|
static |
Tests whether a name is valie.
Returns true if the specified string satisfies the requirements for being a valid facility name.
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.