1 #ifndef __STACKVM_LOGGER_H__ 2 #define __STACKVM_LOGGER_H__ 3 4 /* M-runtime for c++ 5 * Copyright (C) 2005-2008 Vladimir Menshakov 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 23 #include "singleton.h" 24 #include "fmt.h" 25 #include <stdio.h> 26 #include "export_mrt.h" 27 28 #define LL_DEBUG 0 29 #define LL_NOTICE 1 30 #define LL_WARN 6 31 #define LL_ERROR 7 32 33 namespace mrt { 34 35 class MRTAPI ILogger { 36 public: 37 DECLARE_SINGLETON(ILogger); 38 39 ILogger(); 40 virtual ~ILogger(); 41 42 void assign(const std::string &file); 43 void close(); 44 45 void set_log_level(const int level); 46 const char * get_log_level_name(const int level); 47 48 void log(const int level, const char *file, const int line, const std::string &str); get_lines_counter()49 unsigned get_lines_counter() const { return _lines; } 50 51 private: 52 int _level; 53 unsigned _lines; 54 55 ILogger(const ILogger &); 56 const ILogger& operator=(const ILogger &); 57 58 FILE *fd; 59 }; 60 61 PUBLIC_SINGLETON(MRTAPI, Logger, ILogger); 62 } 63 64 #define LOG_DEBUG(msg) mrt::ILogger::get_instance()->log(LL_DEBUG, __FILE__, __LINE__, mrt::format_string msg) 65 #define LOG_NOTICE(msg) mrt::ILogger::get_instance()->log(LL_NOTICE, __FILE__, __LINE__, mrt::format_string msg) 66 #define LOG_WARN(msg) mrt::ILogger::get_instance()->log(LL_WARN, __FILE__, __LINE__, mrt::format_string msg) 67 #define LOG_ERROR(msg) mrt::ILogger::get_instance()->log(LL_ERROR, __FILE__, __LINE__, mrt::format_string msg) 68 69 #endif 70 71