LCG Project | LCG Applications Area | |
$Date: 2004/06/28 17:34:30 $ |
This guide explains how to use the Message Service from a component (refer to how to create a component), and how to configure it.
The message to be reported to message service is composed using a MessageStream. The user can define as many message streams as required. The MessageStream sets the message source (typically the name or identification of the component), the severity level and the message text itself.
Typical method implementation looks like this:
#include "SealKernel/MesssageStream.h"
using namespace seal;
MyComponent::doSomething() { MessageStream log(this,"MyComponent"); MessageStream error(this,"MyComponent",Msg::Error); ... log << "This is a message at INFO level since is the default" << flush; log(Msg::Warning) << "This is a WARNING this time" << flush; error << "This is an ERROR" << flush; ... }
The MessageStream is communicating with the MessageService when the the message is complete (flush or endmsg) or at destruction (out of scope). The MessageService is located at the context of the component or any context up in the hierarchy (this is why "this" appears in the constructor arguments ). If no MessageService is located then the standard std::cout is used instead.
The MessageStream is also initialized with a name (message source name) and a initial severity level (Msg::Info by default). Only a communication is established if the message severity level is equal or higher than the current level threshold for that source or the general one.
The output of the previous code snip is as follows:
MyComponent INFO This is a message at INFO level since is the default MyComponent WARNING This is a WARNING this time MyComponent ERROR This is an ERROR
For the time being the MessageService offers two configuration parameters: