{"id":185222,"date":"2013-07-01T16:29:04","date_gmt":"2013-07-01T12:29:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=185222"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=185222","title":{"rendered":"<span class=\"post_title\">\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043b\u043e\u0433\u0433\u0435\u0440 \u0434\u043b\u044f C++<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u0438\u0441\u043a\u0430\u043b \u0443\u0434\u043e\u0431\u043d\u044b\u0439, \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043b\u043e\u0433\u0433\u0435\u0440 \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432. \u041d\u043e \u044f \u0438\u0441\u043a\u0430\u043b \u043d\u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0434\u043b\u044f \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u043d\u0433\u0430 \u043a\u043e\u0434, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0432\u0435\u0434\u0435\u043d\u0438\u044e \u043b\u043e\u0433\u0430. \u0421\u043f\u0443\u0441\u0442\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 Log 4 C++ \u2014 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043a\u043b\u0430\u0441\u0441, \u0434\u043b\u044f \u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0430, \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0438\u0434\u0435\u044f\u0445 Log 4 C++.<\/p>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u043e\u0432\u043e\u0440\u043a\u043e\u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0435\u0449\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u043d\u043a\u0438\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0438 \u043e\u043f\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0431\u044b\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u043c\u043d\u043e\u0439 \u0432 \u043c\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043b\u0430\u0441\u0441, \u0447\u0442\u043e \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u0438\u043d \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 <code>.h<\/code> \u0444\u0430\u0439\u043b \u0438 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u044f\u0442\u0435\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0435\u0433\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043d\u0443\u0436\u0434\u044b. <br \/>  <i>\u041a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0447\u0430\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0421++11, \u043e\u0434\u043d\u0430\u043a\u043e, \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0430\u0440\u043e\u0439 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u0440\u0443\u0434\u0430..<\/i><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430<\/h4>\n<p>  <code>CLogger<\/code> \u2014 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0438\u043c\u0435\u043d <code>framework::Diagnostics<\/code>. \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0438\u043c\u0435\u043d <code>framework::Threading<\/code>. \u041e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u2014 <code>CIntraProcessLock<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>CLogger<\/code> \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u0415\u0441\u043b\u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0438\u0442\u0441\u044f \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>CNoLock<\/code>. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043b\u043e\u0433\u0433\u0435\u0440\u0430, \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u0430, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043b\u0438\u0431\u043e \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439, \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u044b <code>Lock()<\/code> \u0438 <code>Unlock()<\/code>.<\/p>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043b\u043e\u0433\u0433\u0435\u0440\u0430:  <\/p>\n<pre><code class=\"cpp\">using namespace framework::Diagnostics; using namespace framework::Threading; CLogger&lt;CNolock&gt; logger(LogLevel::Info, _T(&quot;MyApp&quot;)); <\/code><\/pre>\n<p>  \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:  <\/p>\n<ul>\n<li><code>LogLevel<\/code> \u2014 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f <code>framework::Diagnostics::LogLevel<\/code>. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0432\u043e\u0434\u0430, \u043e\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043b\u043e\u0433.<\/li>\n<li><code>Name<\/code> \u2014 \u0438\u043c\u044f, \u0434\u0430\u043d\u043d\u043e\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u043b\u043e\u0433\u0433\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0436\u0443\u0440\u043d\u0430\u043b\u0430.<\/li>\n<li><code>logItems<\/code> \u2014 \u044d\u0442\u043e \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u043c\u0430\u0441\u043a\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0436\u0443\u0440\u043d\u0430\u043b\u0430. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0440\u0443\u0442\u0441\u044f \u0438\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f <code>framework::Diagnostics::LogItem<\/code>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u044d\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0442\u0430\u043a:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/293\/0bf\/700\/2930bf7007bacbe4a026d67cf3f20f9a.png\"\/><br \/>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0432 \u043b\u043e\u0433 \u0432\u044b\u0432\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u0442\u0430 \u0438 \u0432\u0440\u0435\u043c\u044f, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043f\u0440\u0438\u043d\u044f\u043b\u043e \u0431\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<br \/> \n<pre><code class=\"cpp\">CLogger&lt;CNoLock&gt; logger(LogLevel::Info, _T(&quot;MyApp&quot;), static_cast&lt;int&gt;(LogItem::DateTime)); <\/code><\/pre>\n<\/li>\n<\/ul>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0432\u043e\u0434\u0430. \u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443 \u0432\u044b\u0432\u043e\u0434\u0430 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u00ab\u0443\u0440\u043e\u0432\u0435\u043d\u044c\u00bb, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0443\u0440\u043e\u0432\u0435\u043d\u044c <code>Info<\/code> \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432 cout, \u0430 <code>Error<\/code> \u2014 \u0432 \u0444\u0430\u0439\u043b. \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">logger.AddOutputStream(std::wcout, false, LogLevel::Error); logger.AddOutputStream(new std::wofstream(&quot;c:\\\\temp\\\\myapp.log&quot;), true, framework::Diagnostics::LogLevel::Info); <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 <code>AddOutputStream<\/code> \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:  <\/p>\n<ul>\n<li><code>os<\/code> \u2014 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>ostream<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>cout<\/code> \u0438\u043b\u0438 <code>wcout<\/code>.<\/li>\n<li><code>own<\/code> \u2014 \u0435\u0441\u043b\u0438 <code>true<\/code>, \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>CLogger<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>delete<\/code>, \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 ostream. \u042d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0431\u0435\u0437\u044b\u043c\u044f\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>filestream<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 (\u0441\u043c. \u043a\u043e\u0434 \u0432\u044b\u0448\u0435).<\/li>\n<li><code>LogLevel<\/code> \u2014 \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438, \u0440\u0430\u0432\u043d\u044b\u0435 \u0438\u043b\u0438 \u0432\u044b\u0448\u0435 \u044d\u0442\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0432\u043e\u0434\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u0440\u043e\u0432\u0435\u043d\u044c <code>CLogger<\/code>.<\/li>\n<\/ul>\n<p>  \u041d\u0443 \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043b\u043e\u0433, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0440\u043e\u0441<code> WRITELOG<\/code>. \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">WRITELOG(logger, framework::Diagnostics::LogLevel::Info, _T(&quot;Program starting&quot;)); WRITELOG(logger, framework::Diagnostics::LogLevel::Warn, _T(&quot;Something may have gone wrong&quot;)); WRITELOG(logger, framework::Diagnostics::LogLevel::Error, _T(&quot;Something did go wrong&quot;)); WRITELOG(logger, framework::Diagnostics::LogLevel::Info, _T(&quot;Program Ending&quot;)); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/h4>\n<p>  <\/p>\n<h5>main.cpp<\/h5>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &quot;threading.h&quot; #include &quot;Logger.h&quot; #include &lt;fstream&gt;  using namespace framework::Diagnostics; using namespace framework::Threading;  int _tmain(int argc, _TCHAR* argv[]) {     CLogger&lt;CNolock&gt; logger(LogLevel::Info, _T(&quot;MyApp&quot;));      logger.AddOutputStream(std::wcout, false, LogLevel::Error);     logger.AddOutputStream(new std::wofstream(&quot;c:\\\\temp\\\\myapp.log&quot;), true, framework::Diagnostics::LogLevel::Info);              WRITELOG(logger, framework::Diagnostics::LogLevel::Info, _T(&quot;Program starting&quot;));     WRITELOG(logger, framework::Diagnostics::LogLevel::Warn, _T(&quot;Something may have gone wrong&quot;));     WRITELOG(logger, framework::Diagnostics::LogLevel::Error, _T(&quot;Something did go wrong&quot;));     WRITELOG(logger, framework::Diagnostics::LogLevel::Info, _T(&quot;Program Ending&quot;));      return 0; } <\/code><\/pre>\n<p>  <\/p>\n<h5>tstring.h<\/h5>\n<p>  <\/p>\n<pre><code class=\"cpp\">#ifndef TSTRING_H_DEFINED #define TSTRING_H_DEFINED  #include &lt;string&gt; #include &lt;tchar.h&gt;  #if defined(UNICODE) || defined(_UNICODE) \t#define tstring std::wstring \t#define tout std::wcout \t#define tin std::wcin \t#define tostream std::wostream \t#define tofstream std::wofstream \t#define tifstream std::wifstream \t#define tfstream std::wfstream #else \t#define tstring std::string \t#define tout std::cout \t#define tin std::cin \t#define tostream std::ostream \t#define tofstream std::ofstream \t#define tifstream std::ifstream \t#define tfstream std::fstream #endif  #endif <\/code><\/pre>\n<p>  <\/p>\n<h5>threading.h<\/h5>\n<p>  <\/p>\n<pre><code class=\"cpp\">#pragma once  #include &lt;windows.h&gt;  namespace framework { \tnamespace Threading \t{ \t\tclass CIntraProcessLock \t\t{ \t\tpublic: \t\t\tCIntraProcessLock() \t\t\t{ \t\t\t\tInitializeCriticalSection(&m_cs); \t\t\t} \t\t\t \t\t\t~CIntraProcessLock() \t\t\t{ \t\t\t\tDeleteCriticalSection(&m_cs); \t\t\t}  \t\t\tinline bool Lock() \t\t\t{ \t\t\t\treturn TryEnterCriticalSection(&m_cs) &gt; 0 ? true : false; \t\t\t}  \t\t\tinline void Unlock() \t\t\t{ \t\t\t\treturn LeaveCriticalSection(&m_cs); \t\t\t}  \t\tprivate: \t\t\tCRITICAL_SECTION m_cs; \t\t};  \t\tclass CNoLock \t\t{ \t\tpublic: \t\t\tinline bool Lock()  \t\t\t{  \t\t\t\treturn true;  \t\t\t} \t\t\t \t\t\tinline void Unlock() \t\t\t{ \t\t\t\treturn; \t\t\t} \t\t}; \t} } <\/code><\/pre>\n<p>  <\/p>\n<h5>Logger.h<\/h5>\n<p>  <\/p>\n<pre><code class=\"cpp\">#pragma once  #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;stdio.h&gt; #include &lt;Windows.h&gt; #include &lt;time.h&gt; #include &quot;tstring.h&quot; #include &quot;threading.h&quot;  #ifdef UNICODE #define WRITELOG(logObj, level, text) logObj.Log(level, __FILEW__, __LINE__, __FUNCTIONW__, text); #else #define WRITELOG(logObj, level, text) logObj.Log(level, __FILEW__, __LINE__, __FUNCTION__, text); #endif  using namespace std;  namespace framework {\t \tnamespace Diagnostics \t{ \t\tenum class LogLevel \t\t{ \t\t\tInfo,\t\t \t\t\tDebug, \t\t\tWarn, \t\t\tError \t\t};  \t\tenum class LogItem \t\t{ \t\t\tFilename\t= 0x1, \t\t\tLineNumber\t= 0x2, \t\t\tFunction    = 0x4, \t\t\tDateTime\t= 0x8,\t\t \t\t\tThreadId\t= 0x10, \t\t\tLoggerName  = 0x20, \t\t\tLogLevel\t= 0x40 \t\t};  \t\ttemplate &lt;class ThreadingProtection&gt; class CLogger \t\t{ \t\tprivate: \t\t\tstruct StreamInfo \t\t\t{ \t\t\t\ttostream* pStream; \t\t\t\tbool owned; \t\t\t\tLogLevel level;  \t\t\t\tStreamInfo(wostream* pStream, bool owned, LogLevel level) \t\t\t\t{ \t\t\t\t\tthis-&gt;pStream = pStream; \t\t\t\t\tthis-&gt;owned = owned; \t\t\t\t\tthis-&gt;level = level; \t\t\t\t} \t\t\t};  \t\tpublic: \t\t\tCLogger(framework::Diagnostics::LogLevel level, LPCTSTR name,  \t\t\t\tint loggableItems = static_cast&lt;int&gt;(LogItem::Function) | static_cast&lt;int&gt;(LogItem::LineNumber) |  \t\t\t\tstatic_cast&lt;int&gt;(LogItem::DateTime) | stattic_cast&lt;int&gt;(LogItem::LoggerName) | \t\t\t\tstatic_cast&lt;int&gt;(LogItem::LogLevel)) : m_level(level), m_name(name), m_loggableItem(loggableItems) \t\t\t{\t\t\t\t \t\t\t}  \t\t\t~CLogger() \t\t\t{ \t\t\t}  \t\t\tvoid AddOutputStream(tostream& os, bool own, LogLevel level) \t\t\t{ \t\t\t\tAddOutputStream(&os, own, level); \t\t\t}  \t\t\tvoid AddOutputStream(tostream& os, bool own) \t\t\t{ \t\t\t\tAddOutputStream(os, own, m_level); \t\t\t}  \t\t\tvoid AddOutputStream(tostream* os, bool own) \t\t\t{ \t\t\t\tAddOutputStream(os, own, m_level); \t\t\t}  \t\t\tvoid AddOutputStream(tostream* os, bool own, LogLevel level) \t\t\t{ \t\t\t\tStreamInfo si(os, own, level); \t\t\t\tm_outputStreams.push_back(si); \t\t\t} \t\t\t \t\t\tvoid ClearOutputStreams() \t\t\t{ \t\t\t\tfor(vector&lt;StreamInfo&gt;::iterator iter = m_outputStreams.begin(); iter &lt; m_outputStreams.end(); iter++) \t\t\t\t{ \t\t\t\t\tif(iter-&gt;owned) delete iter-&gt;pStream; \t\t\t\t}  \t\t\t\tm_outputStreams.clear(); \t\t\t}  \t\t\tvoid Log(LogLevel level, LPCTSTR file, INT line, LPCTSTR func, LPCTSTR text) \t\t\t{ \t\t\t\tm_threadProtect.Lock();  \t\t\t\tfor(vector&lt;StreamInfo&gt;::iterator iter = m_outputStreams.begin(); iter &lt; m_outputStreams.end(); iter++) \t\t\t\t{ \t\t\t\t\tif(level &lt; iter-&gt;level) \t\t\t\t\t{ \t\t\t\t\t\tcontinue; \t\t\t\t\t}  \t\t\t\t\tbool written = false; \t\t\t\t\ttostream * pStream = iter-&gt;pStream; \t\t\t\t \t\t\t\t\tif(m_loggableItem & static_cast&lt;int&gt;(LogItem::DateTime)) \t\t\t\t\t\twritten = write_datetime(written, pStream); \t\t\t\t \t\t\t\t\tif(m_loggableItem & static_cast&lt;int&gt;(LogItem::ThreadId)) \t\t\t\t\t\twritten = write&lt;int&gt;(GetCurrentThreadId(), written, pStream);  \t\t\t\t\tif(m_loggableItem & static_cast&lt;int&gt;(LogItem::LoggerName)) \t\t\t\t\t\twritten = write&lt;LPCTSTR&gt;(m_name.c_str(), written, pStream);  \t\t\t\t\tif(m_loggableItem & static_cast&lt;int&gt;(LogItem::LogLevel)) \t\t\t\t\t{ \t\t\t\t\t\tTCHAR strLevel[4]; \t\t\t\t\t\tloglevel_toString(level, strLevel); \t\t\t\t\t\twritten = write&lt;LPCTSTR&gt;(strLevel, written, pStream); \t\t\t\t\t}  \t\t\t\t\tif(m_loggableItem & static_cast&lt;int&gt;(LogItem::Function)) \t\t\t\t\t\twritten = write&lt;LPCTSTR&gt;(func, written, pStream);  \t\t\t\t\tif(m_loggableItem & static_cast&lt;int&gt;(LogItem::Filename)) \t\t\t\t\t\twritten = write&lt;LPCTSTR&gt;(file, written, pStream);  \t\t\t\t\tif(m_loggableItem & static_cast&lt;int&gt;(LogItem::LineNumber)) \t\t\t\t\t\twritten = write&lt;int&gt;(line, written, pStream); \t\t\t\t\t\t\t\t \t\t\t\t\twritten = write&lt;LPCTSTR&gt;(text, written, pStream);  \t\t\t\t\tif(written) \t\t\t\t\t{ \t\t\t\t\t\t(*pStream) &lt;&lt; endl; \t\t\t\t\t\tpStream-&gt;flush(); \t\t\t\t\t} \t\t\t\t}  \t\t\t\tm_threadProtect.Unlock(); \t\t\t}  \t\tprivate: \t\t\tint m_loggableItem; \t\t\tLogLevel m_level; \t\t\ttstring m_name;  \t\t\tvector&lt;StreamInfo&gt; m_outputStreams; \t\t\tThreadingProtection m_threadProtect; \t \t\t\ttemplate &lt;class T&gt; inline bool write(T data, bool written, wostream* strm) \t\t\t{ \t\t\t\tif(written == true) \t\t\t\t{ \t\t\t\t\t(*strm) &lt;&lt; _T(&quot; &quot;); \t\t\t\t}  \t\t\t\t(*strm) &lt;&lt; data; \t\t\t\treturn true; \t\t\t}  \t\t\tinline bool write_datetime(bool written, wostream* strm) \t\t\t{ \t\t\t\tif(written == true) \t\t\t\t{ \t\t\t\t\t(*strm) &lt;&lt; _T(&quot; &quot;); \t\t\t\t}  \t\t\t\ttime_t szClock; \t\t\t\ttm newTime;  \t\t\t\ttime( &szClock ); \t\t\t\tlocaltime_s(&newTime, &szClock); \t\t\t \t\t\t\tTCHAR strDate[10] = { _T('\\0') }; \t\t\t\tTCHAR strTime[10] = { _T('\\0') };  \t\t\t\t_tstrdate_s(strDate, 10); \t\t\t\t_tstrtime_s(strTime, 10);  \t\t\t\t(*strm) &lt;&lt; strDate &lt;&lt; _T(&quot; &quot;) &lt;&lt; strTime; \t\t \t\t\t\treturn true; \t\t\t}  \t\t\tvoid loglevel_toString(LogLevel level, LPTSTR strLevel) \t\t\t{ \t\t\t\tswitch (level) \t\t\t\t{ \t\t\t\tcase LogLevel::Error: \t\t\t\t\t_tcscpy_s(strLevel, 4, _T(&quot;ERR&quot;)); \t\t\t\t\tbreak;  \t\t\t\tcase LogLevel::Warn: \t\t\t\t\t_tcscpy_s(strLevel, 4, _T(&quot;WRN&quot;)); \t\t\t\t\tbreak;  \t\t\t\tcase LogLevel::Info: \t\t\t\t\t_tcscpy_s(strLevel, 4, _T(&quot;INF&quot;)); \t\t\t\t\tbreak;  \t\t\t\tcase LogLevel::Debug: \t\t\t\t\t_tcscpy_s(strLevel, 4, _T(&quot;DBG&quot;)); \t\t\t\t\tbreak; \t\t\t\t} \t\t\t} \t\t}; \t} } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b<\/h4>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/92c\/696\/005\/92c69600551b0c376b423f4a89604182.png\"\/><br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/ecf\/2b8\/e48\/ecf2b8e48231a854f4cc1bc7ac0a621c.png\"\/>    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/185222\/\"> http:\/\/habrahabr.ru\/post\/185222\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u0438\u0441\u043a\u0430\u043b \u0443\u0434\u043e\u0431\u043d\u044b\u0439, \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043b\u043e\u0433\u0433\u0435\u0440 \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432. \u041d\u043e \u044f \u0438\u0441\u043a\u0430\u043b \u043d\u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0434\u043b\u044f \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u043d\u0433\u0430 \u043a\u043e\u0434, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0432\u0435\u0434\u0435\u043d\u0438\u044e \u043b\u043e\u0433\u0430. \u0421\u043f\u0443\u0441\u0442\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 Log 4 C++ \u2014 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043a\u043b\u0430\u0441\u0441, \u0434\u043b\u044f \u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0430, \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0438\u0434\u0435\u044f\u0445 Log 4 C++.<\/p>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u043e\u0432\u043e\u0440\u043a\u043e\u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0435\u0449\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u043d\u043a\u0438\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0438 \u043e\u043f\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0431\u044b\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u043c\u043d\u043e\u0439 \u0432 \u043c\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043b\u0430\u0441\u0441, \u0447\u0442\u043e \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u0438\u043d \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 <code>.h<\/code> \u0444\u0430\u0439\u043b \u0438 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u044f\u0442\u0435\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0435\u0433\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043d\u0443\u0436\u0434\u044b. <br \/>  <i>\u041a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0447\u0430\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0421++11, \u043e\u0434\u043d\u0430\u043a\u043e, \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0430\u0440\u043e\u0439 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u0440\u0443\u0434\u0430..<\/i>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-185222","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/185222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=185222"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/185222\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=185222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=185222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=185222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}