📄 log.h
字号:
//// Copyright (c) 2003 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#ifndef DXR3PLAYER_UTIL_LOG_H#define DXR3PLAYER_UTIL_LOG_H//------------------------------------------------------------------------------#include <cstdarg>//------------------------------------------------------------------------------/** * Class for logging functions. */class Log{public: /** * The log message type. */ typedef enum type_t { /// Normal message NORMAL, /// Warning message WARNING, /// Debug message DEBUG, /// Debug message to be displayed only when verbosity is /// turned on VERBOSE_DEBUG, /// Error message ERROR, /// Fatal error message FATAL };private: /** * The logger class. */ class Logger { public: /** * Get the only instance of the logger. */ static Logger& getInstance(); private: /** * The log file. */ void* logFile; /** * Indicate if verbose logging is required. */ bool isVerbose; /** * The last type. */ type_t lastType; /** * Construct the logger. */ Logger(); /** * Destroy the logger. */ ~Logger(); public: /** * Log a message with the given type. */ void log(type_t type, const char* format, std::va_list& ap); /** * Continue the message logged previously. It will use the * same type, and will not print the time in front. */ void cont(const char* format, std::va_list& ap); private: /** * Indicate if the given type should be logged. */ bool shouldLog(type_t type); };public: /** * Log a message with the given type. */ static void log(type_t type, const char* format, std::va_list& ap); /** * Log a message with the given type. */ static void log(type_t type, const char* format, ...); /** * Log a normal message. */ static void normal(const char* format, ...); /** * Log a warning message. */ static void warning(const char* format, ...); /** * Log a debug message. */ static void debug(const char* format, ...); /** * Log a verbose debug message. */ static void verboseDebug(const char* format, ...); /** * Log an error message. */ static void error(const char* format, ...); /** * Log a fatal error message. */ static void fatal(const char* format, ...); /** * Continue the previous log message (with the same type) */ static void cont(const char* format, va_list& ap); /** * Continue the previous log message (with the same type) */ static void cont(const char* format, ...);};//------------------------------------------------------------------------------// Inline definitions//------------------------------------------------------------------------------inline Log::Logger& Log::Logger::getInstance(){ static Logger logger; return logger;}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline void Log::log(type_t type, const char* format, va_list& ap){ Logger::getInstance().log(type, format, ap);}//------------------------------------------------------------------------------inline void Log::log(type_t type, const char* format, ...){ va_list ap; va_start(ap, format); log(type, format, ap); va_end(ap);}//------------------------------------------------------------------------------inline void Log::normal(const char* format, ...){ va_list ap; va_start(ap, format); log(NORMAL, format, ap); va_end(ap);}//------------------------------------------------------------------------------inline void Log::warning(const char* format, ...){ va_list ap; va_start(ap, format); log(WARNING, format, ap); va_end(ap);}//------------------------------------------------------------------------------inline void Log::debug(const char* format, ...){ va_list ap; va_start(ap, format); log(DEBUG, format, ap); va_end(ap);}//------------------------------------------------------------------------------inline void Log::verboseDebug(const char* format, ...){ va_list ap; va_start(ap, format); log(VERBOSE_DEBUG, format, ap); va_end(ap);}//------------------------------------------------------------------------------inline void Log::error(const char* format, ...){ va_list ap; va_start(ap, format); log(ERROR, format, ap); va_end(ap);}//------------------------------------------------------------------------------inline void Log::fatal(const char* format, ...){ va_list ap; va_start(ap, format); log(FATAL, format, ap); va_end(ap);}//------------------------------------------------------------------------------inline void Log::cont(const char* format, va_list& ap){ Logger::getInstance().cont(format, ap);}//------------------------------------------------------------------------------inline void Log::cont(const char* format, ...){ va_list ap; va_start(ap, format); cont(format, ap); va_end(ap);}//------------------------------------------------------------------------------#endif //DXR3PLAYER_UTIL_LOG_H// Local variables:// mode: c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -