📄 log.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 <liblpp/Log.h>#include "LogImpl.h"#include <iostream>#include <string>#include <ctime>#include <map>#include <algorithm>#include <vector>#include <iomanip>//=============================================================================LPP_NAMESPACE_BEGIN//=============================================================================LogException::LogException(const std::string& message)throw(): message(message){ }LogException::~LogException()throw(){ }const char* LogException::what() const throw(){ return message.c_str();}/*============================================================================. | Constructord / Destructors | '============================================================================*/Log::Log(const std::string& name, LogWriter& writer, const LogLevel& level): LogStream(NATURAL_INFO_STREAM_NAME, name, writer, level), debug("debug", name, writer, DEFAULT_LEVEL_DEBUG), info("info", name, writer, DEFAULT_LEVEL_INFO), warn("warn", name, writer, DEFAULT_LEVEL_WARN), error("error", name, writer, DEFAULT_LEVEL_ERROR), fatal("fatal", name, writer, DEFAULT_LEVEL_FATAL){}Log::~Log(){}/*============================================================================. | Static methods. | '============================================================================*/bool Log::useThreads = false;const LogForm* Log::configuredLogForm(const LogForm* logForm){ static const LogForm* configuredLogForm = 0; if(logForm) { configuredLogForm = logForm; } return configuredLogForm;}const ThreadMill* Log::configuredThreadMill(const ThreadMill* threadMill){ static const ThreadMill* configuredThreadMill = 0; if(threadMill) { configuredThreadMill = threadMill; } return configuredThreadMill;}void Log::setUseThreads(bool useThreads){ if(useThreads) { if(!Log::useThreads) { // Turn threads on. } } else { if(Log::useThreads) { // Turn threads off. } } Log::useThreads = useThreads;}Log& Log::getLog(std::ostream& os){ return Log::getLog(DEFAULT_LOG_NAME, os);}Log& Log::getLog(const char* name, std::ostream& os){ return getLog(std::string(name), os);}Log& Log::getLog(const std::string& name, std::ostream& os){ LogMap& logMap = LogImpl::logMap(); if(!logMap[name]) { logMap[name] = new LogImpl(name, os); logMap[name]->setLogForm(configuredLogForm()); if(useThreads) { logMap[name]->setThreadMill(configuredThreadMill()); logMap[name]->startThread(); } } return *logMap[name];}void Log::closedown(){ LogMap& logMap = LogImpl::logMap(); LogMap::iterator i = logMap.begin(); for(; i != logMap.end(); i++) { delete (*i).second; //logMap.erase(i); }}//=============================================================================LPP_NAMESPACE_END//=============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -