| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# MsgStream Class Reference

`#include <GaudiKernel/MsgStream.h>`

Collaboration diagram for MsgStream:

[legend]

List of all members.

## Detailed Description

Definition of the MsgStream class used to transmit messages.

This class is intended to ease the use of error logging to the message service

Author:
  M.Frank

  Sebastien Ponce

Definition at line 25 of file MsgStream.h.

## Public Member Functions
| MsgStream (IMessageSvc *svc, int buffer_length=128)
| Standard constructor: Connect to message service for output.
| MsgStream (IMessageSvc *svc, const std::string &source, int buffer_length=128)
| Standard constructor: Connect to message service for output.
| MsgStream (const MsgStream &msg)
| Copy constructor.
virtual | ~MsgStream ()
| Standard destructor.
MsgStream & | report (int lvl)
| Initialize report of new message: activate if print level is sufficient.
virtual MsgStream & | doOutput ()
| Output method.
const std::string & | buffer () const
| Access string buffer.
std::ostringstream & | stream ()
| Access string MsgStream.
void | setMsgSvc (IMessageSvc *svc)
| Update `IMessageSvc` pointer.
void | setLevel (int level)
| Update outputlevel.
MSG::Level | level ()
| Retrieve output level.
MSG::Level | currentLevel ()
| Retrieve current stream output level.
void | activate ()
| Activate MsgStream.
void | deactivate ()
| Deactivate MsgStream.
bool | isActive () const
| Accessor: is MsgStream active.
MsgStream & | flush ()
MsgStream & | write (const char *buff, int len)
MsgStream & | operator<< (MsgStream &(*_f)(MsgStream &))
| Accept MsgStream modifiers.
MsgStream & | operator<< (std::ostream &(*_f)(std::ostream &))
| Accept oMsgStream modifiers.
MsgStream & | operator<< (std::ios &(*_f)(std::ios &))
| Accept ios modifiers.
MsgStream & | operator<< (MSG::Level level)
| Accept MsgStream activation using MsgStreamer operator.
MsgStream & | operator<< (longlong arg)
MsgStream & | operator<< (std::ios_base &(*_f)(std::ios_base &))
| Accept ios base class modifiers.
long | flags () const
| IOS emulation.
long | flags (FLAG_TYPE v)
long | setf (FLAG_TYPE v)
int | width () const
int | width (int v)
char | fill () const
char | fill (char v)
int | precision () const
int | precision (int v)
int | rdstate () const
int | good () const
int | eof () const
int | bad () const
long | setf (FLAG_TYPE _f, FLAG_TYPE _m)
void | unsetf (FLAG_TYPE _l)
void | clear (STATE_TYPE _i=std::ios_base::failbit)
void | setColor (MSG::Color col)
| Set the text color.
void | setColor (MSG::Color fg, MSG::Color bg)
| Set the foreground and background colors.
void | resetColor ()
| Reset the colors to defaults.
## Protected Attributes
IMessageSvc * | m_service
| Pointer to message service if buffer has send.
std::string | m_buffer
| Use standard string for information buffering.
std::string | m_source
| Use std::string for source information to be passed to the message service.
std::ostringstream | m_stream
| String MsgStream associated to buffer.
bool | m_active
| Flag set to true if formatting engine is active.
MSG::Level | m_level
| Debug level of the message service.
MSG::Level | m_currLevel
| Current debug level.
bool | m_useColors
| use colors
## Private Types
typedef std::ios_base::fmtflags | FLAG_TYPE
| Error return code in case ios modification is requested for inactive streams.
typedef std::ios_base::iostate | STATE_TYPE

## Member Typedef Documentation

typedef std::ios_base::fmtflags MsgStream::FLAG_TYPE`[private]`

Error return code in case ios modification is requested for inactive streams.

Definition at line 30 of file MsgStream.h.

typedef std::ios_base::iostate MsgStream::STATE_TYPE`[private]`

Definition at line 31 of file MsgStream.h.

## Constructor & Destructor Documentation

MsgStream::MsgStream | ( | IMessageSvc * | svc,
|  | int | buffer_length = `128` |
| ) |  |  |

Standard constructor: Connect to message service for output.

Definition at line 31 of file MsgStream.cpp.

    00032 : m_service(svc),
    00033   m_source(""),
    00034   m_active(false)
    00035 {
    00036   setLevel((0==svc) ? MSG::INFO : svc->outputLevel());
    00037   m_useColors = (0==svc) ? false : svc->useColor();
    00038 }

MsgStream::MsgStream | ( | IMessageSvc * | svc,
|  | const std::string & | source,
|  | int | buffer_length = `128` |
| ) |  |  |

Standard constructor: Connect to message service for output.

Definition at line 40 of file MsgStream.cpp.

    00041 : m_service(svc),
    00042   m_source(source),
    00043   m_active(false)
    00044 {
    00045   setLevel((0==svc) ? MSG::INFO : svc->outputLevel(source));
    00046   m_useColors = (0==svc) ? false : svc->useColor();
    00047 }

MsgStream::MsgStream | ( | const MsgStream & | msg | ) | `[inline]`

Copy constructor.

Definition at line 55 of file MsgStream.h.

    00056     : m_service(msg.m_service),
    00057       m_source(msg.m_source),
    00058       m_active(msg.m_active),
    00059       m_level(msg.m_level),
    00060       m_useColors(msg.m_useColors)
    00061   {
    00062   }

MsgStream::~MsgStream | ( |  | ) | `[virtual]`

Standard destructor.

Definition at line 49 of file MsgStream.cpp.

    00049                          {
    00050 }

## Member Function Documentation

MsgStream& MsgStream::report | ( | int | lvl | ) | `[inline]`

Initialize report of new message: activate if print level is sufficient.

Definition at line 66 of file MsgStream.h.

    00066                                {
    00067     lvl = (lvl >= MSG::NUM_LEVELS) ?
    00068       MSG::ALWAYS : (lvl<MSG::NIL) ? MSG::NIL : lvl;
    00069     ((m_currLevel=MSG::Level(lvl)) >= level()) ? activate() : deactivate();
    00070     return *this;
    00071   }

MsgStream & MsgStream::doOutput | ( |  | ) | `[virtual]`

Output method.

Definition at line 52 of file MsgStream.cpp.

    00052                                      {
    00053   if ( isActive() )   {
    00054     Message msg(m_source,m_currLevel,m_stream.str());
    00055     if ( m_service != 0 )   {
    00056       m_service->reportMessage (msg, m_currLevel);
    00057     }
    00058     else     {
    00059       std::cout << msg << std::endl;
    00060     }
    00061   }
    00062
    00063   m_stream.str("");
    00064   return *this;
    00065 }

const std::string& MsgStream::buffer | ( |  | ) | const`[inline]`

Access string buffer.

Definition at line 75 of file MsgStream.h.

    00075                                   {
    00076     return m_buffer;
    00077   }

std::ostringstream& MsgStream::stream | ( |  | ) | `[inline]`

Access string MsgStream.

Definition at line 79 of file MsgStream.h.

    00079                                {
    00080     return m_stream;
    00081   }

void MsgStream::setMsgSvc | ( | IMessageSvc * | svc | ) | `[inline]`

Update `IMessageSvc` pointer.

Definition at line 83 of file MsgStream.h.

    00083                                      {
    00084     m_service = svc;
    00085   }

void MsgStream::setLevel | ( | int | level | ) | `[inline]`

Update outputlevel.

Definition at line 87 of file MsgStream.h.

    00087                               {
    00088     level = (level >= MSG::NUM_LEVELS) ?
    00089       MSG::ALWAYS : (level<MSG::NIL) ? MSG::NIL : level;
    00090     m_level = MSG::Level(level);
    00091   }

MSG::Level MsgStream::level | ( |  | ) | `[inline]`

Retrieve output level.

Definition at line 93 of file MsgStream.h.

    00093                      {
    00094     return m_level;
    00095   }

MSG::Level MsgStream::currentLevel | ( |  | ) | `[inline]`

Retrieve current stream output level.

Definition at line 97 of file MsgStream.h.

    00097                             {
    00098     return m_currLevel;
    00099   }

void MsgStream::activate | ( |  | ) | `[inline]`

Activate MsgStream.

Definition at line 101 of file MsgStream.h.

    00101                       {
    00102     m_active = true;
    00103   }

void MsgStream::deactivate | ( |  | ) | `[inline]`

Deactivate MsgStream.

Definition at line 105 of file MsgStream.h.

    00105                         {
    00106     m_active = false;
    00107   }

bool MsgStream::isActive | ( |  | ) | const`[inline]`

Accessor: is MsgStream active.

Definition at line 109 of file MsgStream.h.

    00109                            {
    00110     return m_active;
    00111   }

MsgStream& MsgStream::flush | ( |  | ) | `[inline]`

Definition at line 113 of file MsgStream.h.

    00113                         {
    00114     if ( isActive() ) m_stream.flush();
    00115     return *this;
    00116   }

MsgStream& MsgStream::write | ( | const char * | buff,
|  | int | len |
| ) |  |  | `[inline]`

Definition at line 118 of file MsgStream.h.

    00118                                               {
    00119     if ( isActive() ) m_stream.write(buff, len);
    00120     return *this;
    00121   }

MsgStream& MsgStream::operator<< | ( | MsgStream &(*)(MsgStream &) | _f | ) | `[inline]`

Accept MsgStream modifiers.

Definition at line 123 of file MsgStream.h.

    00123                                                          {
    00124     if ( isActive() ) _f(*this);
    00125     return *this;
    00126   }

MsgStream& MsgStream::operator<< | ( | std::ostream &(*)(std::ostream &) | _f | ) | `[inline]`

Accept oMsgStream modifiers.

Definition at line 128 of file MsgStream.h.

    00128                                                            {
    00129     if ( isActive() ) _f(m_stream);
    00130     return *this;
    00131   }

MsgStream& MsgStream::operator<< | ( | std::ios &(*)(std::ios &) | _f | ) | `[inline]`

Accept ios modifiers.

Definition at line 133 of file MsgStream.h.

    00133                                                    {
    00134     if ( isActive() ) _f(m_stream);
    00135     return *this;
    00136   }

MsgStream& MsgStream::operator<< | ( | MSG::Level | level | ) | `[inline]`

Accept MsgStream activation using MsgStreamer operator.

Definition at line 138 of file MsgStream.h.

    00138                                           {
    00139     return report(level);
    00140   }

MsgStream& MsgStream::operator<< | ( | longlong | arg | ) | `[inline]`

Definition at line 141 of file MsgStream.h.

    00141                                       {
    00142     if(isActive()) {
    00143 #ifdef _WIN32
    00144       int flg = m_stream.flags();
    00145       char buf[128];
    00146       (flg & std::ios::hex) ?
    00147         ::sprintf(buf,"%I64x",arg) : ::sprintf(buf,"%I64d",arg);
    00148       m_stream << buf;
    00149 #else
    00150       m_stream << arg;
    00151 #endif
    00152     }
    00153     return *this;
    00154   }

MsgStream& MsgStream::operator<< | ( | std::ios_base &(*)(std::ios_base &) | _f | ) | `[inline]`

Accept ios base class modifiers.

Definition at line 157 of file MsgStream.h.

    00157                                                              {
    00158     if ( isActive() ) _f(m_stream);
    00159     return *this;
    00160   }

long MsgStream::flags | ( |  | ) | const`[inline]`

IOS emulation.

Definition at line 163 of file MsgStream.h.

    00163                      {
    00164     return isActive() ? m_stream.flags()    : 0;
    00165   }

long MsgStream::flags | ( | FLAG_TYPE | v | ) | `[inline]`

Definition at line 166 of file MsgStream.h.

    00166                           {
    00167     return isActive() ? m_stream.flags(v)  :  0;
    00168   }

long MsgStream::setf | ( | FLAG_TYPE | v | ) | `[inline]`

Definition at line 169 of file MsgStream.h.

    00169                          {
    00170     return isActive() ? m_stream.setf(v)  :  0;
    00171   }

int MsgStream::width | ( |  | ) | const`[inline]`

Definition at line 172 of file MsgStream.h.

    00172                     {
    00173     return isActive() ? m_stream.width()    : 0;
    00174   }

int MsgStream::width | ( | int | v | ) | `[inline]`

Definition at line 175 of file MsgStream.h.

    00175                    {
    00176     return isActive() ? m_stream.width(v)    : 0;
    00177   }

char MsgStream::fill | ( |  | ) | const`[inline]`

Definition at line 178 of file MsgStream.h.

    00178                     {
    00179     return isActive() ? m_stream.fill()     : -1;
    00180   }

char MsgStream::fill | ( | char | v | ) | `[inline]`

Definition at line 181 of file MsgStream.h.

    00181                     {
    00182     return isActive() ? m_stream.fill(v)     : -1;
    00183   }

int MsgStream::precision | ( |  | ) | const`[inline]`

Definition at line 184 of file MsgStream.h.

    00184                          {
    00185     return isActive() ? m_stream.precision(): 0;
    00186   }

int MsgStream::precision | ( | int | v | ) | `[inline]`

Definition at line 187 of file MsgStream.h.

    00187                        {
    00188     return isActive() ? m_stream.precision(v): 0;
    00189   }

int MsgStream::rdstate | ( |  | ) | const`[inline]`

Definition at line 190 of file MsgStream.h.

    00190                        {
    00191     return isActive() ? m_stream.rdstate () : std::ios_base::failbit;
    00192   }

int MsgStream::good | ( | void |  | ) | const`[inline]`

Definition at line 193 of file MsgStream.h.

    00193                     {
    00194     return isActive() ? m_stream.good ()    : 0;
    00195   }

int MsgStream::eof | ( |  | ) | const`[inline]`

Definition at line 196 of file MsgStream.h.

    00196                    {
    00197     return isActive() ? m_stream.eof ()     : 0;
    00198   }

int MsgStream::bad | ( |  | ) | const`[inline]`

Definition at line 199 of file MsgStream.h.

    00199                    {
    00200     return isActive() ? m_stream.bad()      : 0;
    00201   }

long MsgStream::setf | ( | FLAG_TYPE | _f,
|  | FLAG_TYPE | _m |
| ) |  |  | `[inline]`

Definition at line 202 of file MsgStream.h.

    00202                                         {
    00203     return isActive() ? m_stream.setf(_f, _m)   : 0;
    00204   }

void MsgStream::unsetf | ( | FLAG_TYPE | _l | ) | `[inline]`

Definition at line 205 of file MsgStream.h.

    00205                                {
    00206     if ( isActive() ) m_stream.unsetf(_l);
    00207   }

void MsgStream::clear | ( | STATE_TYPE | _i = `std::ios_base::failbit` | ) | `[inline]`

Definition at line 208 of file MsgStream.h.

    00208                                                   {
    00209     if ( isActive() ) m_stream.clear(_i);
    00210   }

void MsgStream::setColor | ( | MSG::Color | col | ) |

Set the text color.

Definition at line 67 of file MsgStream.cpp.

    00067                                      {
    00068 #ifndef _WIN32
    00069   if ( m_useColors)   {
    00070     int fc = 90 + col;
    00071     m_stream << "[" << fc << ";1m";
    00072   }
    00073 #endif
    00074 }

void MsgStream::setColor | ( | MSG::Color | fg,
|  | MSG::Color | bg |
| ) |  |  |

Set the foreground and background colors.

Definition at line 76 of file MsgStream.cpp.

    00076                                                  {
    00077 #ifndef _WIN32
    00078   if ( m_useColors )   {
    00079     int fc = 90 + fg;
    00080     m_stream << "[" << fc;
    00081     int bc = 100 + bg;
    00082       m_stream << ";" << bc;
    00083     m_stream << ";1m";
    00084   }
    00085 #endif
    00086 }

void MsgStream::resetColor | ( |  | ) |

Reset the colors to defaults.

Definition at line 88 of file MsgStream.cpp.

    00088                            {
    00089 #ifndef _WIN32
    00090   if ( m_useColors )   {
    00091     m_stream << "[m" << m_service->getLogColor(m_currLevel);
    00092   }
    00093 #endif
    00094 }

## Member Data Documentation

IMessageSvc* MsgStream::m_service`[protected]`

Pointer to message service if buffer has send.

Definition at line 34 of file MsgStream.h.

std::string MsgStream::m_buffer`[protected]`

Use standard string for information buffering.

Definition at line 36 of file MsgStream.h.

std::string MsgStream::m_source`[protected]`

Use std::string for source information to be passed to the message service.

Definition at line 38 of file MsgStream.h.

std::ostringstream MsgStream::m_stream`[protected]`

String MsgStream associated to buffer.

Definition at line 40 of file MsgStream.h.

bool MsgStream::m_active`[protected]`

Flag set to true if formatting engine is active.

Definition at line 42 of file MsgStream.h.

MSG::Level MsgStream::m_level`[protected]`

Debug level of the message service.

Definition at line 44 of file MsgStream.h.

MSG::Level MsgStream::m_currLevel`[protected]`

Current debug level.

Definition at line 46 of file MsgStream.h.

bool MsgStream::m_useColors`[protected]`

use colors

Definition at line 48 of file MsgStream.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r3/GaudiKernel/GaudiKernel/MsgStream.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r3/GaudiKernel/src/Lib/MsgStream.cpp