📄 logwriter.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_LOGWRITER_H_#define _LPP_LOGWRITER_H_#include <liblpp/Types.h>#include <liblpp/LogFlag.h>#include <liblpp/LogMask.h>#include <liblpp/LogForm.h>#include <liblpp/Thread.h>#include <map>#include <string>#include <iostream>#include <queue>#include <ctime>//=============================================================================LPP_NAMESPACE_BEGIN//=============================================================================class LogOutput;typedef std::map<std::string, LogOutput*> LogOutputMap;typedef std::queue<LogMessage> MessageQueue;/** * The LogWriter class maintains a list of LogOutput objects * and potentially a LogMessage queue if threaded queueing is * enabled. **/class LogWriter: public Runnable{private: MessageQueue messageQueue; LogOutputMap logOutputMap; bool isDone; Thread* thread; const ThreadMill* threadMill; //friend class LogImpl; void flushQueue(); void flush(); public: LogWriter(); virtual ~LogWriter(); /*------------------------------------------------------------------------. | LogOutput Management | '------------------------------------------------------------------------*/ /** * Add a LogOutput to this LogWriter. * @param name The name by which to refer to the * new LogOutput. * @param logMask The LogMask to apply to * the new LogOutput. * @param os A std::ostream to attach to * the new LogOutput. **/ void addOutput(const std::string& name, const LogMask& mask, std::ostream& os); /** * Modify a LogOutput added to this LogWriter. * @param name The name of the LogOutput to modify. * @param logMask The new LogMask to apply to * the named LogOutput. * @param modType The method by which to apply the new LogMask. **/ void setLogMask(const std::string& name, const LogMask& mask, ModType modType = REPLACE); /** * Get the LogMask for a LogOutput added to this LogWriter. * @param name The name of the LogOutput to query. * @return The LogMask assigned to the specified LogOutput * of this LogWriter. **/ LogMask getLogMask(const std::string& name); /** * Change the internal LogForm formatting object of a * LogOutput added to this LogWriter. * @param name The name of the LogOutput to modify. * @param format The new LogForm object to use. **/ void setLogForm(const std::string& name, const LogForm* const format); /** * Delete a LogOutput from this LogWriter. * @param name The name of the LogOutput to delete. **/ void delOutput(const std::string& name); /*------------------------------------------------------------------------. | std::ostream Management | '------------------------------------------------------------------------*/ /** * Attach an ostream to one of the LogOutputs * of this LogWriter. * @param name The LogOutput to attach the std::ostream to. * @param os The std::ostream attach. **/ void attachOstream(const std::string& name, std::ostream& os); /** * Remove an output stream from one of the LogOutputs * of this LogWriter. * @param name The LogOutput to remove the std::ostream from. * @param os The std::ostream remove. **/ void removeOstream(const std::string& name, std::ostream& os); /*------------------------------------------------------------------------. | Action Interface | '------------------------------------------------------------------------*/ /** * Start processing the LogMessage queue on the * current thread. Note this method will block * untill a call to stopThread() is made from * another thread. Therefore for the calling * application to achieve a separately threaded * message queue it is the *caller's* responsibility * to initiate the new thread and to call this * method from that thread. * @param thread A thread callback object implementing * the (thread library) specifics of threading required * by the Log's queueing system. **/ //void startThread(Thread* thread); /** * Set the ThreadMill for this LogWriter. * This turns multithreading on. * @patam threadcallFactory The ThreadCallfactory to use. **/ virtual void setThreadMill(const ThreadMill* threadMill); /** * Clear the ThreadMill for this LogWriter. * This turns multithreading off. **/ virtual void clrThreadMill(); /** * Start processing the LogMessage queue on a * separate thread. **/ void startThread(); /** * Stop processing the LogMessage queue. Note * this ethod will block untl the current * message queue is flushed and the thread * has terminated. (joined). **/ void stopThread(); // Runnable Interface void run(); // process queue void end(); /** * Write a LogMessage to each LogOutput maintained * by this LogWriter. * @param message The LogMessage to write. **/ void write(LogMessage& message);};//=============================================================================LPP_NAMESPACE_END//=============================================================================#endif /*_LPP_LOGWRITER_H_*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -