1: 2: 3: /********************** 4: * * 5: * COMPILER INCLUDES * 6: * * 7: **********************/ 8: 9: 10: #include <cassert> 11: 12: 13: /********************* 14: * * 15: * PROJECT INCLUDES * 16: * * 17: *********************/ 18: 19: 20: #include "loghandle.h" 21: #include "wwwi/singleton.h" 22: #include "wwwi/string.h" 23: 24: 25: using std::strchr; 26: using std::string; 27: using WWWI::GetSingleton; 28: using WWWI::StringDuplicate; 29: 30: 31: /************************** 32: * * 33: * LOGHANDLE CONSTRUCTOR * 34: * * 35: **************************/ 36: 37: 38: LogHandle::LogHandle(LogFacility i_lf, LogPriority i_ly) { 39: m_lf = i_lf; 40: m_ly = i_ly; 41: m_lyBase = i_ly; 42: } 43: 44: 45: /**************** 46: * * 47: * OPERATOR () * 48: * * 49: ****************/ 50: 51: 52: void LogHandle::operator()() { 53: this->Flush(); 54: m_ly = m_lyBase; 55: } 56: 57: 58: /**************** 59: * * 60: * OPERATOR << * 61: * * 62: ****************/ 63: 64: 65: LogHandle &LogHandle::operator<<(LogPriority i_ly) { 66: if (i_ly!=m_ly) { 67: this->Flush(); 68: m_ly = i_ly; 69: } 70: return *this; 71: } 72: 73: 74: /***************** 75: * * 76: * METHOD FLUSH * 77: * * 78: *****************/ 79: 80: 81: void LogHandle::Flush() { 82: char *strBuffer; 83: char *strEnd; 84: char *strPos; 85: string xtrLine; 86: MINDLogPtr lgp = GetSingleton<MINDLog>(); 87: 88: strBuffer = StringDuplicate(this->str().c_str()); 89: this->str(string()); 90: this->clear(); 91: 92: strPos = strBuffer; 93: while ((strEnd = strchr(strPos,'\n'))!=NULL) { 94: *strEnd++ = 0; 95: lgp->Log(m_lf,m_ly,strPos); 96: strPos = strEnd; 97: } 98: if (*strPos!=0) lgp->Log(m_lf,m_ly,strPos); 99: delete[] strBuffer; 100: } 101: 102: 103: /************************* 104: * * 105: * LOGHANDLE DESTRUCTOR * 106: * * 107: *************************/ 108: 109: 110: LogHandle::~LogHandle() { 111: this->Flush(); 112: } 113: 114: 115: 116: