📄 logimpl.cpp
字号:
/*============================================================================. | 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 | '============================================================================*/#include "LogImpl.h"//=============================================================================LPP_NAMESPACE_BEGIN//=============================================================================//Log& LogImpl::log = Log::getLog();LogImpl::LogImpl(const std::string& name, std::ostream& os): Log(name, writer, defaultLogLevel()), name(name), writer(){ writer.addOutput(NATURAL_LOG_OUTPUT_NAME, defaultLogMask(), os);}LogImpl::~LogImpl(){// logMap().erase(name); LogStreamMap::iterator i; for(i = logStreamMap.begin(); i != logStreamMap.end(); i++) { delete (*i).second; }}/*============================================================================. | LoggerImpl Methods | '============================================================================*//*========================================================================. | Dynamic Interface | '========================================================================*/const std::string& LogImpl::getName() const { return name; }/*------------------------------------------------------------------------. | LogOutput Management | '------------------------------------------------------------------------*/void LogImpl::addOutput(const std::string& name, const LogMask& mask, std::ostream& os){ writer.addOutput(name, mask, os);}void LogImpl::setLogMask(const LogMask& mask, ModType modType){ setLogMask(NATURAL_LOG_OUTPUT_NAME, mask, modType);}void LogImpl::setLogMaskLevel(const LogLevel& level, ModType modType){ setLogMaskLevel(NATURAL_LOG_OUTPUT_NAME, level, modType);}LogMask LogImpl::getLogMask(){ return getLogMask(NATURAL_LOG_OUTPUT_NAME);}void LogImpl::setLogMask(const std::string& name, const LogMask& mask, ModType modType){ writer.setLogMask(name, mask, modType);}void LogImpl::setLogMaskLevel(const std::string& name, const LogLevel& level, ModType modType){ setLogMask(name, LogMask::levelToMask(level), modType);}LogMask LogImpl::getLogMask(const std::string& name){ return writer.getLogMask(name);}void LogImpl::delOutput(const std::string& name){ writer.delOutput(name);}/*----------------------------------------------------------------------------. : LogStream Management : '----------------------------------------------------------------------------*/void LogImpl::addLogStream(const std::string& name, const LogLevel& level){ LogStream* logStream = logStreamMap[name]; if(!logStream) { logStreamMap[name] = new LogStream(name, this->name, writer, checkLogLevel(level)); } else { modLogStream(name, level); info << "LogStream already exists. Modifying instead: "; //info << name << " " << level << std::endl; }}void LogImpl::modLogStream(const std::string& name, const LogLevel& level){ LogStream* logStream = logStreamMap[name]; if(logStream) { logStream->setLogLevel(level); } else { addLogStream(name, level); //info << "Automatically added LogStream " << name << " " << level << std::endl; }}void LogImpl::delLogStream(const std::string& name){ LogStream* logStream = logStreamMap[name]; if(!logStream) { error << "Attempt to delete non existent LogStream " << name << std::endl; } else { if(name != NATURAL_INFO_STREAM_NAME) { logStreamMap.erase(name); delete logStream; } }}/*----------------------------------------------------------------------------. : User defined LogStream access : '----------------------------------------------------------------------------*/LogStream& LogImpl::to(std::string name){ LogStream* logStream = logStreamMap[name]; if(!logStream) { addLogStream(name, defaultLogLevel()); logStream = logStreamMap[name]; if(!logStream) { error << "Failed to create info stream " << name << std::endl; } } return *logStream;}LogStream& LogImpl::to(std::string name, std::string info){ return static_cast<LogStream&>(to(name) << info);}/*------------------------------------------------------------------------. | std::ostream Management | '------------------------------------------------------------------------*/void LogImpl::attachOstream(std::ostream& os){ attachOstream(NATURAL_LOG_OUTPUT_NAME, os);}void LogImpl::removeOstream(std::ostream& os){ removeOstream(NATURAL_LOG_OUTPUT_NAME, os);} void LogImpl::attachOstream(const std::string& name, std::ostream& os){ writer.attachOstream(name, os);}void LogImpl::removeOstream(const std::string& name, std::ostream& os){ writer.removeOstream(name, os);}void LogImpl::setThreadMill(const ThreadMill* threadMill){ writer.setThreadMill(threadMill);}void LogImpl::startThread(){ writer.startThread();}void LogImpl::stopThread(){ writer.stopThread();}void LogImpl::close(){ stopThread();}void LogImpl::setLogForm(const LogForm* const format){ setLogForm(NATURAL_LOG_OUTPUT_NAME, format);}void LogImpl::setLogForm(const std::string& name, const LogForm* const format){ writer.setLogForm(name, format);}/*============================================================================. | Static Methods | '============================================================================*/const LogLevel& LogImpl::checkLogLevel(const LogLevel& logLevel){ static const LogLevel logLevelMax(sizeof(LogMask) * 8); return logLevel <= logLevelMax ? logLevel : logLevelMax;}const LogLevel& LogImpl::defaultLogLevel(const LogLevel* logLevel){ static LogLevel defaultLogLevel(DEFAULT_LEVEL_NONE); if(logLevel) // Change value { defaultLogLevel = checkLogLevel(*logLevel); } return defaultLogLevel;}const LogMask& LogImpl::defaultLogMask(const LogMask* logMask){ static LogMask defaultLogMask = LogMask::levelToMask(DEFAULT_LEVEL_DEBUG); if(logMask) // Change value { defaultLogMask = *logMask; } return defaultLogMask;}//=============================================================================LPP_NAMESPACE_END//=============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -