Gaudi Framework, version v20r2

Generated: 18 Jul 2008

MsgStream Class Reference

#include <GaudiKernel/MsgStream.h>

Collaboration diagram for MsgStream:

Collaboration graph
[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 24 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.
MsgStreamreport (int lvl)
 Initialize report of new message: activate if print level is sufficient.
virtual MsgStreamdoOutput ()
 Output method.
const std::stringbuffer () const
 Access string buffer.
std::ostringstreamstream ()
 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.
MsgStreamflush ()
MsgStreamwrite (const char *buff, int len)
MsgStreamoperator<< (MsgStream &(*_f)(MsgStream &))
 Accept MsgStream modifiers.
MsgStreamoperator<< (std::ostream &(*_f)(std::ostream &))
 Accept oMsgStream modifiers.
MsgStreamoperator<< (std::ios &(*_f)(std::ios &))
 Accept ios modifiers.
MsgStreamoperator<< (MSG::Level level)
 Accept MsgStream activation using MsgStreamer operator.
MsgStreamoperator<< (longlong arg)
MsgStreamoperator<< (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

IMessageSvcm_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 29 of file MsgStream.h.

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

Definition at line 30 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.

References MSG::INFO, m_useColors, IMessageSvc::outputLevel(), setLevel(), and IMessageSvc::useColor().

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.

References MSG::INFO, m_useColors, IMessageSvc::outputLevel(), setLevel(), and IMessageSvc::useColor().

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 54 of file MsgStream.h.

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

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 65 of file MsgStream.h.

References activate(), MSG::ALWAYS, deactivate(), level(), m_currLevel, MSG::NIL, and MSG::NUM_LEVELS.

Referenced by operator<<().

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

MsgStream & MsgStream::doOutput (  )  [virtual]

Output method.

Definition at line 52 of file MsgStream.cpp.

References std::cout, std::endl(), isActive(), m_currLevel, m_service, m_source, m_stream, IMessageSvc::outputLevel(), IMessageSvc::reportMessage(), IMessageSvc::setOutputLevel(), and std::basic_ostringstream< _CharT, _Traits, _Alloc >::str().

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

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

Access string buffer.

Definition at line 74 of file MsgStream.h.

References m_buffer.

00074                                   {
00075     return m_buffer;
00076   }

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

Access string MsgStream.

Definition at line 78 of file MsgStream.h.

References m_stream.

Referenced by operator<<().

00078                                {
00079     return m_stream;
00080   }

void MsgStream::setMsgSvc ( IMessageSvc svc  )  [inline]

Update IMessageSvc pointer.

Definition at line 82 of file MsgStream.h.

References m_service.

00082                                      {
00083     m_service = svc;
00084   }

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

Update outputlevel.

Definition at line 86 of file MsgStream.h.

References MSG::ALWAYS, m_level, MSG::NIL, and MSG::NUM_LEVELS.

Referenced by HistorySvc::initialize(), and MsgStream().

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

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

Retrieve output level.

Definition at line 92 of file MsgStream.h.

References m_level.

Referenced by THistSvc::finalize(), report(), and RootHistCnv::RFileCnv::updateRep().

00092                      {
00093     return m_level;
00094   }

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

Retrieve current stream output level.

Definition at line 96 of file MsgStream.h.

References m_currLevel.

00096                             {
00097     return m_currLevel;
00098   }

void MsgStream::activate (  )  [inline]

Activate MsgStream.

Definition at line 100 of file MsgStream.h.

References m_active.

Referenced by report().

00100                       {
00101     m_active = true;
00102   }

void MsgStream::deactivate (  )  [inline]

Deactivate MsgStream.

Definition at line 104 of file MsgStream.h.

References m_active.

Referenced by report().

00104                         {
00105     m_active = false;
00106   }

bool MsgStream::isActive (  )  const [inline]

Accessor: is MsgStream active.

Definition at line 108 of file MsgStream.h.

References m_active.

Referenced by bad(), HbookCnv::HRWNTupleCnv::book(), HbookCnv::HCWNTupleCnv::book(), clear(), doOutput(), eof(), fill(), flags(), flush(), good(), operator<<(), operator<<(), precision(), rdstate(), setf(), unsetf(), width(), write(), and HbookCnv::HConverter::writeObject().

00108                            {
00109     return m_active;
00110   }

MsgStream& MsgStream::flush (  )  [inline]

Definition at line 112 of file MsgStream.h.

References std::basic_ostringstream< _CharT, _Traits, _Alloc >::flush(), isActive(), and m_stream.

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

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

Definition at line 117 of file MsgStream.h.

References isActive(), m_stream, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::write().

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

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

Accept MsgStream modifiers.

Definition at line 122 of file MsgStream.h.

References isActive().

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

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

Accept oMsgStream modifiers.

Definition at line 127 of file MsgStream.h.

References isActive(), and m_stream.

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

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

Accept ios modifiers.

Definition at line 132 of file MsgStream.h.

References isActive(), and m_stream.

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

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

Accept MsgStream activation using MsgStreamer operator.

Definition at line 137 of file MsgStream.h.

References report().

00137                                           {
00138     return report(level);
00139   }

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

Definition at line 140 of file MsgStream.h.

References std::basic_ostringstream< _CharT, _Traits, _Alloc >::flags(), std::basic_ios< _CharT, _Traits >::hex, isActive(), and m_stream.

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

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

Accept ios base class modifiers.

Definition at line 156 of file MsgStream.h.

References isActive(), and m_stream.

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

long MsgStream::flags (  )  const [inline]

IOS emulation.

Definition at line 162 of file MsgStream.h.

References std::basic_ostringstream< _CharT, _Traits, _Alloc >::flags(), isActive(), and m_stream.

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

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

Definition at line 165 of file MsgStream.h.

References std::basic_ostringstream< _CharT, _Traits, _Alloc >::flags(), isActive(), and m_stream.

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

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

Definition at line 168 of file MsgStream.h.

References isActive(), m_stream, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::setf().

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

int MsgStream::width (  )  const [inline]

Definition at line 171 of file MsgStream.h.

References isActive(), m_stream, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::width().

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

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

Definition at line 174 of file MsgStream.h.

References isActive(), m_stream, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::width().

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

char MsgStream::fill (  )  const [inline]

Definition at line 177 of file MsgStream.h.

References std::basic_ostringstream< _CharT, _Traits, _Alloc >::fill(), isActive(), and m_stream.

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

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

Definition at line 180 of file MsgStream.h.

References std::basic_ostringstream< _CharT, _Traits, _Alloc >::fill(), isActive(), and m_stream.

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

int MsgStream::precision (  )  const [inline]

Definition at line 183 of file MsgStream.h.

References isActive(), m_stream, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::precision().

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

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

Definition at line 186 of file MsgStream.h.

References isActive(), m_stream, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::precision().

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

int MsgStream::rdstate (  )  const [inline]

Definition at line 189 of file MsgStream.h.

References std::ios_base::failbit, isActive(), m_stream, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::rdstate().

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

int MsgStream::good (  )  const [inline]

Definition at line 192 of file MsgStream.h.

References std::basic_ostringstream< _CharT, _Traits, _Alloc >::good(), isActive(), and m_stream.

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

int MsgStream::eof (  )  const [inline]

Definition at line 195 of file MsgStream.h.

References std::basic_ostringstream< _CharT, _Traits, _Alloc >::eof(), isActive(), and m_stream.

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

int MsgStream::bad (  )  const [inline]

Definition at line 198 of file MsgStream.h.

References std::basic_ostringstream< _CharT, _Traits, _Alloc >::bad(), isActive(), and m_stream.

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

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

Definition at line 201 of file MsgStream.h.

References isActive(), m_stream, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::setf().

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

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

Definition at line 204 of file MsgStream.h.

References isActive(), m_stream, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::unsetf().

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

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

Definition at line 207 of file MsgStream.h.

References std::basic_ostringstream< _CharT, _Traits, _Alloc >::clear(), isActive(), and m_stream.

Referenced by ChronoStatSvc::finalize(), and ChronoStatSvc::printStats().

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

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

Set the text color.

Definition at line 70 of file MsgStream.cpp.

References m_stream, and m_useColors.

Referenced by HistorySvc::listProperties(), HistorySvc::registerAlg(), HistorySvc::registerAlgTool(), and HistorySvc::registerSvc().

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

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

Set the foreground and background colors.

Definition at line 79 of file MsgStream.cpp.

References m_stream, and m_useColors.

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

void MsgStream::resetColor (  ) 

Reset the colors to defaults.

Definition at line 91 of file MsgStream.cpp.

References IMessageSvc::getLogColor(), m_currLevel, m_service, m_stream, and m_useColors.

Referenced by HistorySvc::listProperties(), HistorySvc::registerAlg(), HistorySvc::registerAlgTool(), and HistorySvc::registerSvc().

00091                            {
00092 #ifndef _WIN32
00093   if ( m_useColors )   {
00094     m_stream << "" << m_service->getLogColor(m_currLevel);
00095   }
00096 #endif
00097 }


Member Data Documentation

IMessageSvc* MsgStream::m_service [protected]

Pointer to message service if buffer has send.

Definition at line 33 of file MsgStream.h.

Referenced by doOutput(), resetColor(), and setMsgSvc().

std::string MsgStream::m_buffer [protected]

Use standard string for information buffering.

Definition at line 35 of file MsgStream.h.

Referenced by buffer().

std::string MsgStream::m_source [protected]

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

Definition at line 37 of file MsgStream.h.

Referenced by doOutput().

std::ostringstream MsgStream::m_stream [protected]

String MsgStream associated to buffer.

Definition at line 39 of file MsgStream.h.

Referenced by bad(), clear(), doOutput(), eof(), fill(), flags(), flush(), good(), operator<<(), precision(), rdstate(), resetColor(), setColor(), setf(), stream(), unsetf(), width(), and write().

bool MsgStream::m_active [protected]

Flag set to true if formatting engine is active.

Definition at line 41 of file MsgStream.h.

Referenced by activate(), deactivate(), and isActive().

MSG::Level MsgStream::m_level [protected]

Debug level of the message service.

Definition at line 43 of file MsgStream.h.

Referenced by level(), and setLevel().

MSG::Level MsgStream::m_currLevel [protected]

Current debug level.

Definition at line 45 of file MsgStream.h.

Referenced by currentLevel(), doOutput(), report(), and resetColor().

bool MsgStream::m_useColors [protected]

use colors

Definition at line 47 of file MsgStream.h.

Referenced by MsgStream(), resetColor(), and setColor().


The documentation for this class was generated from the following files:
Generated at Fri Jul 18 12:08:39 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004