📄 logform.h
字号:
/*============================================================================. | Copyright (C) 2006 Gareth Buxton | |----------------------------------------------------------------------------| | LogPlusPlus is free software; you can redistribute it and/or | | modify it under the terms of the GNU Lesser General Public | | License as published by the Free Software Foundation; either | | version 2.1 of the License, or (at your option) any later version. | | | | LogPlusPlus 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 | | Lesser General Public License for more details. | | | | You should have received a copy of the GNU Lesser General Public | | License along with this library; if not, write to the Free Software | | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | '============================================================================*/#ifndef _LPP_LOGFORM_H_#define _LPP_LOGFORM_H_#include <liblpp/Types.h>#include <liblpp/LogFlag.h>#include <liblpp/LogStream.h>#include <sstream>#include <string>#include <iomanip>#include <map>//=============================================================================LPP_NAMESPACE_BEGIN//=============================================================================struct LogMessage{ /** * The system time at which this LogMessage * was constructed. **/ time_t time; /** * The LogFlag of the LogStream through which * this LogMessage was sent. **/ const LogFlag flag; /** * The name of the Log this LogMessage * was sent to. **/ const std::string logName; /** * The name of the LogStream this LogMessage * was sent to (as created by a call to * Log::addLogStream(const std::string& name, LogLevel level = MAX_LEVEL); **/ const std::string logStreamName; /** * The text of this LogMessage. **/ const std::string text;private: /** * Only this member function can create instances * of a LogMessage. **/ friend void LogStream::write(const std::string& info) const; /** * Create a LogMessage object. **/ LogMessage(time_t time, const LogFlag& flag, const std::string& logName, const std::string& logStreamName, const std::string& text): time(time), flag(flag), logName(logName), logStreamName(logStreamName), text(text) {}};/** * LogForm is the base class of all classes that are used to * format the messeges through the stream. Implementing * classes should override the * std::string operator()( const LogMessage& message) * member function to provide a new logging format. * **/class LogForm{public: LogForm(); virtual ~LogForm(); /** * This overrided function receives a LogMessage as its * parameter and from that produces a formattes std::string * which will be sent to the LogWriter for output. * @param message The LogMessage to be formatted into a std::string. * @return A std::string formated from the information provided * in the LogMessage. **/ virtual std::string operator()(const LogMessage& message) const;};/*---------------------------------------------------------------------------. | Convienient LogForms | '---------------------------------------------------------------------------*//** * LogFormStd provides a basic output format suitable * for most purposes. The Log name and the LogStream * name are truncated to four characters width to * provide a nicely columated format. * <pre> * Date Time Log Stream Message * * 2007-02-03 00:15:49 core: [log] message to log * 2007-02-03 00:15:49 core:[fatal] message to fatal * 2007-02-03 00:15:49 core:[error] message to error * 2007-02-03 00:15:49 core: [warn] message to warn * 2007-02-03 00:15:49 core: [info] message to info * 2007-02-03 00:15:49 core:[debug] message to debug * 2007-02-03 00:19:31 core:[defin] message to defined * </pre> **/class LogFormStd: public LogForm{public: LogFormStd(); ~LogFormStd(); std::string operator()(const LogMessage& message) const;};enum LogCol{ COL_NONE = -1, COL_BLACK = 0, COL_RED, COL_GREEN, COL_YELLOW, COL_BLUE, COL_MAGENTA, COL_CYAN, COL_WHITE};struct LogColInfo{ std::string logStream; LogCol bCol; LogCol fCol; LogCol dateCol; LogCol timeCol; LogCol lNameCol; LogCol sNameCol; bool bold; bool blink; bool uline; LogColInfo(const std::string& logStream = "" , LogCol bCol = COL_NONE , LogCol fCol = COL_NONE , LogCol dateCol = COL_NONE , LogCol timeCol = COL_NONE , LogCol lNameCol = COL_NONE , LogCol sNameCol = COL_NONE , bool bold = false, bool blink = false, bool uline = false) : logStream(logStream) , bCol(bCol) , fCol(fCol) , dateCol(dateCol) , timeCol(timeCol) , lNameCol(lNameCol) , sNameCol(sNameCol) , bold(bold) , blink(blink) , uline(uline) { }};class LogFormTerm: public LogForm{private: const std::map<std::string, LogColInfo>* logStreamMap; public: LogFormTerm(const std::map<std::string, LogColInfo>* logStreamMap = 0); ~LogFormTerm(); std::string operator()(const LogMessage& message) const;};extern const LogForm* const LOG_FORM_RAW;extern const LogFormStd* const LOG_FORM_STANDARD;extern const LogFormTerm* const LOG_FORM_XTERM;//=============================================================================LPP_NAMESPACE_END//=============================================================================#endif /*_LPP_LOGFORM_H_*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -