slic/include
diff -u -r1.2 -r1.3
--- LogStream.hh 27 Apr 2007 10:27:53 -0000 1.2
+++ LogStream.hh 8 Apr 2008 22:06:12 -0000 1.3
@@ -20,407 +20,407 @@
namespace LOG
{
- enum EManip {
- done,
- head,
- endl
- };
+ enum EManip {
+ done,
+ head,
+ endl
+ };
- enum ELevel {
- none=0,
- always,
- fatal,
- error,
- warning,
- okay,
- verbose,
- debug,
- nlevels
- };
+ enum ELevel {
+ none=0,
+ always,
+ fatal,
+ error,
+ warning,
+ okay,
+ verbose,
+ debug,
+ nlevels
+ };
}
static std::string levelNames[ LOG::nlevels ] =
- { "NONE", "ALWAYS", "FATAL", "ERROR", "WARNING", "OKAY", "VERBOSE", "DEBUG" };
+{ "NONE", "ALWAYS", "FATAL", "ERROR", "WARNING", "OKAY", "VERBOSE", "DEBUG" };
namespace slic
{
- /**
- * LogStream provides methods for logging messages at a certain level. The
- * LogStream has a default level, and if a message's log level is greater
- * than the current log level, it is discarded.
- *
- * The stream operators are overloaded so that the LogStream can be used
- * similarly to std::cout.
- *
- * The manipulator LOG::done should be used to terminate a log message.
- *
- * Some of the code, particularly the handling of ios manipulators,
- * is based on Gaudi's
- * <a href="http://isscvs.cern.ch/cgi-bin/cvsweb.cgi/GaudiKernel/GaudiKernel/MsgStream.h?rev=1.41;content-type=text%2Fplain;cvsroot=Gaudi">MsgStream</a>
- * class.
- */
- class LogStream
- {
-
- public:
-
- LogStream( const std::string& name,
- LOG::ELevel level,
- ostream* os = &std::cout )
- : m_name( name ),
- m_outputLevel( level ),
- m_os( os ),
- m_defaultOutputLevel( level ),
- m_active( true ),
- m_fos( 0 )
- {
- m_messenger = new LogMessenger( this );
- }
-
- LogStream( )
- : m_name( "NONE" ),
- m_outputLevel( LOG::okay ),
- m_os ( &std::cout ),
- m_defaultOutputLevel( LOG::okay ),
- m_active( true ),
- m_fos( 0 ),
- m_messenger( 0 )
- {;}
-
- virtual ~LogStream()
- {
- // FIXME: !!! Deletion of messenger causes seg fault !!!
- //delete m_messenger;
- }
-
- const std::string& getName() const
- {
- return m_name;
- }
-
- bool isActive() const
- {
- return m_active;
- }
-
- LOG::ELevel getOutputLevel() const
- {
- return m_outputLevel;
- }
-
- ostream& getOutputStream() const
- {
- return *m_os;
- }
-
- void setOutputLevel( const LOG::ELevel& outputLevel )
- {
- m_outputLevel = outputLevel;
- }
-
/**
- * Stream the level of this message.
+ * LogStream provides methods for logging messages at a certain level. The
+ * LogStream has a default level, and if a message's log level is greater
+ * than the current log level, it is discarded.
+ *
+ * The stream operators are overloaded so that the LogStream can be used
+ * similarly to std::cout.
+ *
+ * The manipulator LOG::done should be used to terminate a log message.
+ *
+ * Some of the code, particularly the handling of ios manipulators,
+ * is based on Gaudi's
+ * <a href="http://isscvs.cern.ch/cgi-bin/cvsweb.cgi/GaudiKernel/GaudiKernel/MsgStream.h?rev=1.41;content-type=text%2Fplain;cvsroot=Gaudi">MsgStream</a>
+ * class.
*/
- LogStream& operator << ( const LOG::ELevel& x )
+ class LogStream
{
- if ( x <= getOutputLevel() ) {
-
- // Set active state.
- m_active = true;
- // Set the current output level.
- m_outputLevel = x;
+ public:
- }
- else {
-
- // Set inactive state.
- m_active = false;
- }
- return *this;
- }
-
- LogStream& operator << ( const LOG::EManip& x )
- {
- if ( isActive() ) {
- if ( x == LOG::done ) {
- getOutputStream() << std::endl;
- m_outputLevel = m_defaultOutputLevel;
- }
- else if ( x == LOG::head ) {
- getOutputStream() <<
- "[ " << TimeUtil::getAscTime() << " ] :: " <<
- levelNames[ getOutputLevel() ] << " :: " <<
- getName() << " :: ";
- }
- else if ( x == LOG::endl ) {
- getOutputStream() << std::endl;
- }
- }
- return *this;
- }
-
- LogStream& operator << ( const std::_Setiosflags &manip )
- {
- if ( isActive() ) {
- getOutputStream() << manip;
- }
- return *this;
- }
-
- LogStream& operator << (const std::_Resetiosflags &manip)
- {
- if ( isActive() ) {
- getOutputStream() << manip;
- }
- return *this;
- }
+ LogStream( const std::string& name,
+ LOG::ELevel level,
+ ostream* os = &std::cout )
+ : m_name( name ),
+ m_outputLevel( level ),
+ m_os( os ),
+ m_defaultOutputLevel( level ),
+ m_active( true ),
+ m_fos( 0 )
+ {
+ m_messenger = new LogMessenger( this );
+ }
+
+ LogStream( )
+ : m_name( "NONE" ),
+ m_outputLevel( LOG::okay ),
+ m_os ( &std::cout ),
+ m_defaultOutputLevel( LOG::okay ),
+ m_active( true ),
+ m_fos( 0 ),
+ m_messenger( 0 )
+ {;}
+
+ virtual ~LogStream()
+ {
+ // FIXME: !!! Deletion of messenger causes seg fault !!!
+ //delete m_messenger;
+ }
+
+ const std::string& getName() const
+ {
+ return m_name;
+ }
+
+ bool isActive() const
+ {
+ return m_active;
+ }
+
+ LOG::ELevel getOutputLevel() const
+ {
+ return m_outputLevel;
+ }
+
+ ostream& getOutputStream() const
+ {
+ return *m_os;
+ }
+
+ void setOutputLevel( const LOG::ELevel& outputLevel )
+ {
+ m_outputLevel = outputLevel;
+ }
+
+ /**
+ * Stream the level of this message.
+ */
+ LogStream& operator << ( const LOG::ELevel& x )
+ {
+ if ( x <= getOutputLevel() ) {
+
+ // Set active state.
+ m_active = true;
+
+ // Set the current output level.
+ m_outputLevel = x;
+
+ }
+ else {
+
+ // Set inactive state.
+ m_active = false;
+ }
+ return *this;
+ }
+
+ LogStream& operator << ( const LOG::EManip& x )
+ {
+ if ( isActive() ) {
+ if ( x == LOG::done ) {
+ getOutputStream() << std::endl;
+ m_outputLevel = m_defaultOutputLevel;
+ }
+ else if ( x == LOG::head ) {
+ getOutputStream() <<
+ "[ " << TimeUtil::getAscTime() << " ] :: " <<
+ levelNames[ getOutputLevel() ] << " :: " <<
+ getName() << " :: ";
+ }
+ else if ( x == LOG::endl ) {
+ getOutputStream() << std::endl;
+ }
+ }
+ return *this;
+ }
+
+ LogStream& operator << ( const std::_Setiosflags &manip )
+ {
+ if ( isActive() ) {
+ getOutputStream() << manip;
+ }
+ return *this;
+ }
+
+ LogStream& operator << (const std::_Resetiosflags &manip)
+ {
+ if ( isActive() ) {
+ getOutputStream() << manip;
+ }
+ return *this;
+ }
- LogStream& operator << (const std::_Setbase &manip)
- {
- if ( isActive() ) {
- getOutputStream() << manip;
- }
- return *this;
- }
-
- LogStream& operator << (const std::_Setprecision &manip)
- {
- if ( isActive() ) {
- getOutputStream() << manip;
- }
- return *this;
- }
-
- LogStream& operator << (const std::_Setw &manip)
- {
- if ( isActive() ) {
- getOutputStream() << manip;
- }
- return *this;
- }
-
- // Accept ios class modifiers.
- LogStream& operator << ( ios& (*manip)(std::ios&) )
- {
- if ( isActive() ) {
- getOutputStream() << manip;
- }
- return *this;
- }
-
- // Accept ios base class modifiers
- LogStream& operator << ( std::ios_base& (*manip)(std::ios_base&) )
- {
- if ( isActive() ) {
- getOutputStream() << manip;
- }
- return *this;
- }
-
- // Templated stream operator.
- template <typename T>
- LogStream& operator<< ( const T& arg )
- {
- if ( isActive() ) {
- getOutputStream() << arg;
- }
- return *this;
- }
-
- // Specialization stream operator for vector<T>.
- template <typename T>
- LogStream& operator << ( const std::vector<T>& v ) {
- if( isActive() ) {
- for ( typename std::vector<T>::const_iterator i = v.begin();
- i != v.end(); ++i ) { getOutputStream() << *i << " "; }
- }
- return *this;
- }
-
- // std::ios emulation
- int width() const
- {
- return isActive() ? getOutputStream().width() : 0;
- }
-
- int width( int v )
- {
- return isActive() ? getOutputStream().width(v) : 0;
- }
-
-
- long flags() const
- {
- return isActive() ? getOutputStream().flags() : 0;
- }
-
- long flags( std::ios_base::fmtflags v )
- {
- return isActive() ? getOutputStream().flags(v) : 0;
- }
-
- long setf( std::ios_base::fmtflags v )
- {
- return isActive() ? getOutputStream().setf(v) : 0;
- }
-
- char fill() const
- {
- return isActive() ? getOutputStream().fill() : -1;
- }
-
- char fill(char v)
- {
- return isActive() ? getOutputStream().fill(v) : -1;
- }
-
- int precision() const
- {
- return isActive() ? getOutputStream().precision(): 0;
- }
-
- int precision(int v)
- {
- return isActive() ? getOutputStream().precision(v): 0;
- }
-
- int rdstate() const
- {
- return isActive() ? getOutputStream().rdstate () : std::ios_base::failbit;
- }
-
- int good() const
- {
- return isActive() ? getOutputStream().good () : 0;
- }
-
- int eof() const
- {
- return isActive() ? getOutputStream().eof () : 0;
- }
-
- int bad() const
- {
- return isActive() ? getOutputStream().bad() : 0;
- }
-
- long setf( std::ios_base::fmtflags _f, std::ios_base::fmtflags _m )
- {
- return isActive() ? getOutputStream().setf(_f, _m) : 0;
- }
-
- void unsetf( std::ios_base::fmtflags _l )
- {
- if ( isActive() ) {
- getOutputStream().unsetf(_l);
- }
- }
-
- void clear( std::ios_base::iostate _i = std::ios_base::failbit )
- {
- if ( isActive() ) {
- getOutputStream().clear(_i);
- }
- }
-
- // Redirect to a file.
- void setOutputFile(const std::string& file)
- {
- ofstream* m_fos = new ofstream();
- m_fos->open( file.c_str(), ios::app | ios::out );
- m_os = m_fos;
- }
-
- LogStream& debug()
- {
- return *this << LOG::debug;
- }
-
- LogStream& verbose()
- {
- return *this << LOG::verbose;
- }
-
- LogStream& okay()
- {
- return *this << LOG::okay;
- }
-
- LogStream& warning()
- {
- return *this << LOG::warning;
- }
-
- LogStream& error()
- {
- return *this << LOG::error;
- }
-
- LogStream& fatal()
- {
- return *this << LOG::fatal;
- }
-
- LogStream& always()
- {
- return *this << LOG::always;
- }
-
- void log( const std::string& mesg, const LOG::ELevel& level )
- {
- (*this) << level << mesg << LOG::done;
- }
-
- void log( const std::string& mesg )
- {
- log( mesg, getOutputLevel() );
- }
-
- void debug( const std::string& mesg )
- {
- log( mesg, LOG::debug );
- }
-
- void verbose( const std::string& mesg )
- {
- log( mesg, LOG::verbose );
- }
-
- void okay( const std::string& mesg )
- {
- log( mesg, LOG::okay );
- }
-
- void warning( const std::string& mesg )
- {
- log( mesg, LOG::warning );
- }
-
- void error( const std::string& mesg )
- {
- log( mesg, LOG::error );
- }
-
- void fatal( const std::string& mesg )
- {
- log( mesg, LOG::fatal );
- }
-
- void always( const std::string& mesg )
- {
- log( mesg, LOG::always );
- }
-
- private:
- std::string m_name;
- LOG::ELevel m_outputLevel;
- ostream* m_os;
- LOG::ELevel m_defaultOutputLevel;
- bool m_active;
- std::ofstream* m_fos;
- LogMessenger* m_messenger;
- };
+ LogStream& operator << (const std::_Setbase &manip)
+ {
+ if ( isActive() ) {
+ getOutputStream() << manip;
+ }
+ return *this;
+ }
+
+ LogStream& operator << (const std::_Setprecision &manip)
+ {
+ if ( isActive() ) {
+ getOutputStream() << manip;
+ }
+ return *this;
+ }
+
+ LogStream& operator << (const std::_Setw &manip)
+ {
+ if ( isActive() ) {
+ getOutputStream() << manip;
+ }
+ return *this;
+ }
+
+ // Accept ios class modifiers.
+ LogStream& operator << ( ios& (*manip)(std::ios&) )
+ {
+ if ( isActive() ) {
+ getOutputStream() << manip;
+ }
+ return *this;
+ }
+
+ // Accept ios base class modifiers
+ LogStream& operator << ( std::ios_base& (*manip)(std::ios_base&) )
+ {
+ if ( isActive() ) {
+ getOutputStream() << manip;
+ }
+ return *this;
+ }
+
+ // Templated stream operator.
+ template <typename T>
+ LogStream& operator<< ( const T& arg )
+ {
+ if ( isActive() ) {
+ getOutputStream() << arg;
+ }
+ return *this;
+ }
+
+ // Specialization stream operator for vector<T>.
+ template <typename T>
+ LogStream& operator << ( const std::vector<T>& v ) {
+ if( isActive() ) {
+ for ( typename std::vector<T>::const_iterator i = v.begin();
+ i != v.end(); ++i ) { getOutputStream() << *i << " "; }
+ }
+ return *this;
+ }
+
+ // std::ios emulation
+ int width() const
+ {
+ return isActive() ? getOutputStream().width() : 0;
+ }
+
+ int width( int v )
+ {
+ return isActive() ? getOutputStream().width(v) : 0;
+ }
+
+
+ long flags() const
+ {
+ return isActive() ? getOutputStream().flags() : 0;
+ }
+
+ long flags( std::ios_base::fmtflags v )
+ {
+ return isActive() ? getOutputStream().flags(v) : 0;
+ }
+
+ long setf( std::ios_base::fmtflags v )
+ {
+ return isActive() ? getOutputStream().setf(v) : 0;
+ }
+
+ char fill() const
+ {
+ return isActive() ? getOutputStream().fill() : -1;
+ }
+
+ char fill(char v)
+ {
+ return isActive() ? getOutputStream().fill(v) : -1;
+ }
+
+ int precision() const
+ {
+ return isActive() ? getOutputStream().precision(): 0;
+ }
+
+ int precision(int v)
+ {
+ return isActive() ? getOutputStream().precision(v): 0;
+ }
+
+ int rdstate() const
+ {
+ return isActive() ? getOutputStream().rdstate () : std::ios_base::failbit;
+ }
+
+ int good() const
+ {
+ return isActive() ? getOutputStream().good () : 0;
+ }
+
+ int eof() const
+ {
+ return isActive() ? getOutputStream().eof () : 0;
+ }
+
+ int bad() const
+ {
+ return isActive() ? getOutputStream().bad() : 0;
+ }
+
+ long setf( std::ios_base::fmtflags _f, std::ios_base::fmtflags _m )
+ {
+ return isActive() ? getOutputStream().setf(_f, _m) : 0;
+ }
+
+ void unsetf( std::ios_base::fmtflags _l )
+ {
+ if ( isActive() ) {
+ getOutputStream().unsetf(_l);
+ }
+ }
+
+ void clear( std::ios_base::iostate _i = std::ios_base::failbit )
+ {
+ if ( isActive() ) {
+ getOutputStream().clear(_i);
+ }
+ }
+
+ // Redirect to a file.
+ void setOutputFile(const std::string& file)
+ {
+ ofstream* m_fos = new ofstream();
+ m_fos->open( file.c_str(), ios::app | ios::out );
+ m_os = m_fos;
+ }
+
+ LogStream& debug()
+ {
+ return *this << LOG::debug;
+ }
+
+ LogStream& verbose()
+ {
+ return *this << LOG::verbose;
+ }
+
+ LogStream& okay()
+ {
+ return *this << LOG::okay;
+ }
+
+ LogStream& warning()
+ {
+ return *this << LOG::warning;
+ }
+
+ LogStream& error()
+ {
+ return *this << LOG::error;
+ }
+
+ LogStream& fatal()
+ {
+ return *this << LOG::fatal;
+ }
+
+ LogStream& always()
+ {
+ return *this << LOG::always;
+ }
+
+ void log( const std::string& mesg, const LOG::ELevel& level )
+ {
+ (*this) << level << mesg << LOG::done;
+ }
+
+ void log( const std::string& mesg )
+ {
+ log( mesg, getOutputLevel() );
+ }
+
+ void debug( const std::string& mesg )
+ {
+ log( mesg, LOG::debug );
+ }
+
+ void verbose( const std::string& mesg )
+ {
+ log( mesg, LOG::verbose );
+ }
+
+ void okay( const std::string& mesg )
+ {
+ log( mesg, LOG::okay );
+ }
+
+ void warning( const std::string& mesg )
+ {
+ log( mesg, LOG::warning );
+ }
+
+ void error( const std::string& mesg )
+ {
+ log( mesg, LOG::error );
+ }
+
+ void fatal( const std::string& mesg )
+ {
+ log( mesg, LOG::fatal );
+ }
+
+ void always( const std::string& mesg )
+ {
+ log( mesg, LOG::always );
+ }
+
+ private:
+ std::string m_name;
+ LOG::ELevel m_outputLevel;
+ ostream* m_os;
+ LOG::ELevel m_defaultOutputLevel;
+ bool m_active;
+ std::ofstream* m_fos;
+ LogMessenger* m_messenger;
+ };
}
#endif