Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

new_sim_log.h

Go to the documentation of this file.
00001 
00025 #ifndef __NEW_SIM_LOG_H__
00026 #define __NEW_SIM_LOG_H__
00027 
00028 
00029 #ifndef __THREAD_H__
00030 #include "thread.h"
00031 #endif
00032 
00033 #include <stdio.h>
00034 #include <assert.h>
00035 
00037 #define dDefaultLogfile "log"
00038 
00039 /* log file properties */
00040 #define dIpmiLogPropNone 0 
00041 #define dIpmiLogStdOut   1 
00042 #define dIpmiLogStdErr   2 
00043 #define dIpmiLogLogFile  4 
00044 #define dIpmiLogFile     8 
00045 
00046 
00052 class NewSimulatorLog {
00053 protected:
00055    cThreadLock m_lock;
00057    int         m_lock_count;
00059    int         m_open_count;
00060 
00062    bool  m_hex;  // true => print int in hex
00064    bool  m_time; // with time
00066    bool  m_recursive;
00068    bool  m_std_out;
00070    bool  m_std_err;
00072    bool  m_nl;
00074    FILE *m_fd;
00075 
00076    void Start();
00077    void Output( const char *str );
00078 
00079 public:
00080    NewSimulatorLog();
00081    virtual ~NewSimulatorLog();
00082 
00083    bool Open( int properties, const char *filename = "", int max_log_files = 1 );
00084    void Close();
00085 
00089    void Lock() {
00090       m_lock.Lock();
00091       m_lock_count++;
00092    }
00093 
00097    void Unlock() {
00098       m_lock_count--;
00099       assert( m_lock_count >= 0 );
00100       m_lock.Unlock();
00101    }
00102 
00107    void Hex( bool hex = true ) { m_hex = hex; }
00109    bool IsHex()                 { return m_hex;  }
00110 
00115    void Time( bool t = true )  { m_time = t; }
00117    bool WithTime()              { return m_time; }
00118 
00123    void Recursive( bool r )    { m_recursive = true; }
00125    bool IsRecursive()           { return m_recursive; }
00126 
00127    NewSimulatorLog &operator<<( bool b );
00128    NewSimulatorLog &operator<<( unsigned char c );
00129    NewSimulatorLog &operator<<( int i );
00130    NewSimulatorLog &operator<<( unsigned int i );
00131    NewSimulatorLog &operator<<( long l );
00132    NewSimulatorLog &operator<<( double d );
00133    NewSimulatorLog &operator<<( const char *str );
00134 
00135    void Log( const char *fmt, ... );
00136    void Hex( const unsigned char *data, int size );
00137 
00138    void Begin( const char *section, const char *name );
00139    void End();
00140    NewSimulatorLog &Entry( const char *entry );
00141 };
00142 
00144 extern NewSimulatorLog stdlog;
00145 
00146 
00147 #endif

Generated on Mon Apr 26 14:36:48 2010 for New Simulator by  doxygen 1.4.4