49 template <
typename _T>
53 CLog(
_T* _stream,
unsigned char _logLevel)
55 , m_logLevel(_logLevel)
60 unsigned long _ErrorCode,
61 const std::string& _Module,
62 const std::string& _Message)
64 if ((_Severity & m_logLevel) != _Severity)
70 std::stringstream strMsg;
71 strMsg << GetCurTimeString(&_DTBuff) << char(
e_FieldSeparator) << GetSeverityString(_Severity)
76 if (m_stream && m_stream->good())
78 *m_stream << strMsg.str() << std::endl;
83 std::cout << strMsg.str() << std::endl;
88 std::string& GetCurTimeString(std::string* _Buf)
95 gettimeofday(&tv, NULL);
96 tm* tm_now(localtime(&tv.tv_sec));
99 const long milliseconds = tv.tv_usec / 1000;
101 std::stringstream ss;
102 ss <<
"." << milliseconds;
107 const std::string GetSeverityString(
LOG_SEVERITY _Severity)
const 124 std::string GetErrorCode(
unsigned long _ErrorCode)
const 126 std::stringstream sErrCode;
127 sErrCode << _ErrorCode;
128 return sErrCode.str();
134 unsigned char m_logLevel;
155 bool _CreateNew =
false,
159 , m_log_file(_LogFileName.c_str(), (_CreateNew ? std::ios::trunc : std::ios::app) | std::ios::out)
const size_t LOG_DATETIME_BUFF_LEN(25)
Logging to a file.
Definition: Log.h:148
const LPCSTR g_cszLOG_SEVERITY_CRITICAL_ERROR("FLT")
const LPCSTR g_cszLOG_SEVERITY_INFO("INF")
A smart CMutex helper.
Definition: SysHelper.h:275
const LPCSTR g_cszLOG_SEVERITY_DEBUG("DBG")
const LPCSTR g_cszLOG_DATETIME_FRMT("%Y-%m-%d %H:%M:%S")
Log Date/Time format.
enum MiscCommon::ESeverity LOG_SEVERITY
Log's severity's constants.
const LPCSTR g_cszLOG_SEVERITY_WARNING("WRN")
unsigned long gettid()
A system helper, which helps to get a Thread ID of the current thread.
Definition: SysHelper.h:197
std::vector< char > CHARVector_t
An STL vector of char(s).
Definition: def.h:121
#define _T(s)
Use TCHAR instead of char or wchar_t. It will be appropriately translated.
Definition: def.h:85
CLog(_T *_stream, unsigned char _logLevel)
Definition: Log.h:53
CFileLog(const std::string &_LogFileName, bool _CreateNew=false, unsigned char _logLevel=LOG_SEVERITY_INFO|LOG_SEVERITY_WARNING|LOG_SEVERITY_FAULT|LOG_SEVERITY_CRITICAL_ERROR)
Definition: Log.h:154
void push(LOG_SEVERITY _Severity, unsigned long _ErrorCode, const std::string &_Module, const std::string &_Message)
Definition: Log.h:59
const LPCSTR g_cszLOG_SEVERITY_FAULT("ERR")
CLog< std::ostream > CSTDOutLog
ostream specialization of CLog.
Definition: Log.h:141
std::ofstream stream_type
Definition: Log.h:151
ESeverity
Log's severity's constants.
Definition: Log.h:29
A simple template class which represents the Log engine of library.
Definition: Log.h:50
Miscellaneous functions and helpers are located here.
Definition: BOOST_FILESYSTEM.h:21