Changeset 459 for CMT/HEAD/source/cmt_log.h
- Timestamp:
- May 30, 2008, 4:52:11 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
CMT/HEAD/source/cmt_log.h
r11 r459 40 40 #define Log static CmtLog log_instance 41 41 #define log_endl CmtLog::end () 42 #define log if (Cmt::get_debug ()) log_instance << "#CMT> (" << __FILE__ << "-" << __LINE__ << ") " 42 #define log if (Cmt::get_debug ()) log_instance << CmtMessage::prefix () + " (" << __FILE__ << ":" << __LINE__ << ") " 43 //#define log if (Cmt::get_debug ()) log_instance << "#CMT> (" << __FILE__ << "-" << __LINE__ << ") " 43 44 #define log_cont if (Cmt::get_debug ()) log_instance 44 45 46 47 enum CmtMsgLevel 48 { 49 Nil = 0, 50 Debug, 51 Info, 52 Warning, 53 Error, 54 Fatal 55 }; 56 57 class CmtMessage 58 { 59 public: 60 static cmt_string& prefix (); 61 static void set_prefix (const cmt_string& prefix); 62 static CmtMsgLevel& level (); 63 static void set_level (const CmtMsgLevel& level); 64 static bool active (const CmtMsgLevel& level); 65 static void info (const cmt_string& message); 66 static void warning (const cmt_string& message); 67 static void error (const cmt_string& message); 68 static void fatal (const cmt_string& message); 69 70 private: 71 CmtMessage (); 72 static CmtMessage& instance (); 73 cmt_string m_prefix; 74 CmtMsgLevel m_level; 75 }; 76 77 /**---------------------------------------------------------- 78 The CmtMessage default constructor 79 Here are primarily constructed all default definitions 80 */ 81 inline CmtMessage::CmtMessage () 82 : m_prefix ("#CMT--->"), m_level (Info) 83 { } 84 85 /**---------------------------------------------------------- 86 The CmtMessage singleton 87 */ 88 inline CmtMessage& CmtMessage::instance () 89 { 90 static CmtMessage me; 91 return me; 92 } 93 94 inline cmt_string& CmtMessage::prefix () 95 { 96 return instance ().m_prefix; 97 } 98 99 inline void CmtMessage::set_prefix (const cmt_string& prefix) 100 { 101 instance ().m_prefix = prefix; 102 } 103 104 inline CmtMsgLevel& CmtMessage::level () 105 { 106 return instance ().m_level; 107 } 108 109 inline void CmtMessage::set_level (const CmtMsgLevel& level) 110 { 111 instance ().m_level = level; 112 } 113 114 inline bool CmtMessage::active (const CmtMsgLevel& lvl) 115 { 116 return level () <= lvl; 117 } 118 119 inline void CmtMessage::info (const cmt_string& message) 120 { 121 if (active (Info)) 122 cerr << prefix () << " Info: " << message << endl; 123 } 124 125 inline void CmtMessage::warning (const cmt_string& message) 126 { 127 if (active (Warning)) 128 cerr << prefix () << " Warning: " << message << endl; 129 } 130 131 inline void CmtMessage::error (const cmt_string& message) 132 { 133 if (active (Error)) 134 cerr << prefix () << " Error: " << message << endl; 135 } 136 137 inline void CmtMessage::fatal (const cmt_string& message) 138 { 139 if (active (Fatal)) 140 cerr << prefix () << " Fatal: " << message << endl; 141 } 45 142 #endif
Note: See TracChangeset
for help on using the changeset viewer.