00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _SST_LOG_H
00014 #define _SST_LOG_H
00015
00016 #include <stdio.h>
00017 #include <cstdarg>
00018 #include <string>
00019
00020 namespace SST {
00021
00022 template < int ENABLE = 1 >
00023 class Log {
00024 public:
00025 Log( std::string prefix = "", bool enable = true ) :
00026 m_prefix( prefix ), m_enabled( enable )
00027 {}
00028
00029 void enable() {
00030 m_enabled = true;
00031 }
00032 void disable() {
00033 m_enabled = false;
00034 }
00035
00036 void prepend( std::string str ) {
00037 m_prefix = str + m_prefix;
00038 }
00039
00040 inline void write( const std::string fmt, ... )
00041 {
00042 if ( ENABLE ) {
00043
00044 if ( ! m_enabled ) return;
00045
00046 printf( "%s", m_prefix.c_str() );
00047 va_list ap;
00048 va_start( ap,fmt );
00049 vprintf( fmt.c_str(), ap );
00050 va_end( ap);
00051 }
00052 }
00053
00054 private:
00055 std::string m_prefix;
00056 bool m_enabled;
00057 };
00058 }
00059
00060 #endif