48 template <
typename _T>
52 CLog(
_T* _stream,
unsigned char _logLevel)
54 , m_logLevel(_logLevel)
59 unsigned long _ErrorCode,
60 const std::string& _Module,
61 const std::string& _Message)
63 if ((_Severity & m_logLevel) != _Severity)
69 std::stringstream strMsg;
70 strMsg << GetCurTimeString(&_DTBuff) << char(
e_FieldSeparator) << GetSeverityString(_Severity)
75 if (m_stream && m_stream->good())
77 *m_stream << strMsg.str() << std::endl;
82 std::cout << strMsg.str() << std::endl;
87 std::string& GetCurTimeString(std::string* _Buf)
94 gettimeofday(&tv, NULL);
95 tm* tm_now(localtime(&tv.tv_sec));
98 const long milliseconds = tv.tv_usec / 1000;
100 std::stringstream ss;
101 ss <<
"." << milliseconds;
106 const std::string GetSeverityString(
LOG_SEVERITY _Severity)
const 123 std::string GetErrorCode(
unsigned long _ErrorCode)
const 125 std::stringstream sErrCode;
126 sErrCode << _ErrorCode;
127 return sErrCode.str();
133 unsigned char m_logLevel;
154 bool _CreateNew =
false,
157 :
CLog<stream_type>(&m_log_file, _logLevel)
158 , m_log_file(_LogFileName.c_str(), (_CreateNew ?
std::ios::trunc :
std::ios::app) |
std::ios::out)
163 stream_type m_log_file;
const size_t LOG_DATETIME_BUFF_LEN(25)
Logging to a file.
Definition: Log.h:147
const LPCSTR g_cszLOG_SEVERITY_CRITICAL_ERROR("FLT")
const LPCSTR g_cszLOG_SEVERITY_INFO("INF")
A smart CMutex helper.
Definition: SysHelper.h:281
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:204
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:52
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:153
void push(LOG_SEVERITY _Severity, unsigned long _ErrorCode, const std::string &_Module, const std::string &_Message)
Definition: Log.h:58
A Mutex wrapper. Based on pthread calls.
Definition: SysHelper.h:256
const LPCSTR g_cszLOG_SEVERITY_FAULT("ERR")
CLog< std::ostream > CSTDOutLog
ostream specialization of CLog.
Definition: Log.h:140
std::ofstream stream_type
Definition: Log.h:150
ESeverity
Log's severity's constants.
Definition: Log.h:29
A simple template class which represents the Log engine of library.
Definition: Log.h:49
Miscellaneous functions and helpers are located here.
Definition: BOOST_FILESYSTEM.h:21