diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2012-06-29 05:38:03 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2012-06-29 05:38:03 +0000 |
commit | af7e438cfe8ce85e1da234318ed1584e89d952cc (patch) | |
tree | 4cdb1379ef8d6c00389aa89cfb27a404ae2aba56 /plugins/XSoundNotify/DebugLogger.hpp | |
parent | 230623d50baff4e8bf13a8572e0b895bad7b7ed4 (diff) |
only add some plugins and protocols, not adapted
See please maybe not all need us
git-svn-id: http://svn.miranda-ng.org/main/trunk@678 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/XSoundNotify/DebugLogger.hpp')
-rw-r--r-- | plugins/XSoundNotify/DebugLogger.hpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/plugins/XSoundNotify/DebugLogger.hpp b/plugins/XSoundNotify/DebugLogger.hpp new file mode 100644 index 0000000000..3b2c5a5fc1 --- /dev/null +++ b/plugins/XSoundNotify/DebugLogger.hpp @@ -0,0 +1,91 @@ +#ifndef _GRS_DEBUG_LOGGER_H +#define _GRS_DEBUG_LOGGER_H + +#include <fstream> +#include <sstream> +#include <ctime> +#include <memory> + +/** + * Простой логгер, который можно использовать в любом месте для вывода отладочной информации + * При выводе обычного сообщения надо использовать макрос GRS_DEBUG_LOG + * Для вывода сложного сообщения с использованием операторов ввода/вывода макрос GRS_DEBUG_FORMAT_LOG + * Лог сохраняется в рабочем каталоге под именем : grs_debug.log + */ + +namespace grs +{ + +class DebugLogger +{ +public: + class Except : public std::exception + { + public: + virtual const char * what() const throw() { return "pizda rulu"; } + }; + + DebugLogger() + { + try + { + _strm.open("D:\\grs_debug.log", std::ios::app); + } + catch (...) + { + throw Except(); + } + if (!_strm.is_open()) + throw Except(); + + log("Logger started"); + } + + void log(const std::string & str, const char * fileStr = 0, int line = 0) + { + if (!_strm.is_open()) + return ; + + time_t t(time(0)); + struct tm * timeinfo; + timeinfo = localtime (&t); + char timeStr[9]; + strftime (timeStr, 9, "%H:%M:%S", timeinfo); + _strm << "[" << timeStr << "] "; + if (fileStr) + _strm << fileStr << ":" << line<<" "; + _strm <<"# "<< str << std::endl; + } + + static DebugLogger * instance() + { + //static DebugLogger * logger = 0; + static std::auto_ptr<DebugLogger> loggerPtr; + if (loggerPtr.get() == 0) + loggerPtr.reset(new DebugLogger()); + return loggerPtr.get(); + } + +private: + std::ofstream _strm; +}; + +} + +#define GRS_DEBUG_FORMAT_LOG(data) {\ + grs::DebugLogger * l = grs::DebugLogger::instance();\ + if (l != 0) \ + {\ + std::stringstream strm;\ + strm << data;\ + l->log(strm.str(), __FILE__, __LINE__);\ + }\ + } + +#define GRS_DEBUG_LOG(data) {\ + grs::DebugLogger * l = grs::DebugLogger::instance();\ + if (l != 0)\ + l->log(data, __FILE__, __LINE__);\ + } + +#endif |