From af7e438cfe8ce85e1da234318ed1584e89d952cc Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Fri, 29 Jun 2012 05:38:03 +0000 Subject: 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 --- plugins/XSoundNotify/DebugLogger.hpp | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 plugins/XSoundNotify/DebugLogger.hpp (limited to 'plugins/XSoundNotify/DebugLogger.hpp') 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 +#include +#include +#include + +/** + * Простой логгер, который можно использовать в любом месте для вывода отладочной информации + * При выводе обычного сообщения надо использовать макрос 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 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 -- cgit v1.2.3