1 /* 2 ----------------------------------------------------------------------------- 3 This source file is part of OGRE 4 (Object-oriented Graphics Rendering Engine) 5 For the latest info, see http://www.ogre3d.org/ 6 7 Copyright (c) 2000-2014 Torus Knot Software Ltd 8 9 Permission is hereby granted, free of charge, to any person obtaining a copy 10 of this software and associated documentation files (the "Software"), to deal 11 in the Software without restriction, including without limitation the rights 12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 copies of the Software, and to permit persons to whom the Software is 14 furnished to do so, subject to the following conditions: 15 16 The above copyright notice and this permission notice shall be included in 17 all copies or substantial portions of the Software. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 THE SOFTWARE. 26 ----------------------------------------------------------------------------- 27 */ 28 #include "OgreStableHeaders.h" 29 30 namespace Ogre { 31 32 //----------------------------------------------------------------------- 33 template<> LogManager* Singleton<LogManager>::msSingleton = 0; getSingletonPtr(void)34 LogManager* LogManager::getSingletonPtr(void) 35 { 36 return msSingleton; 37 } getSingleton(void)38 LogManager& LogManager::getSingleton(void) 39 { 40 assert( msSingleton ); return ( *msSingleton ); 41 } 42 //----------------------------------------------------------------------- LogManager()43 LogManager::LogManager() 44 { 45 mDefaultLog = NULL; 46 } 47 //----------------------------------------------------------------------- ~LogManager()48 LogManager::~LogManager() 49 { 50 OGRE_LOCK_AUTO_MUTEX; 51 // Destroy all logs 52 LogList::iterator i; 53 for (i = mLogs.begin(); i != mLogs.end(); ++i) 54 { 55 OGRE_DELETE i->second; 56 } 57 } 58 //----------------------------------------------------------------------- createLog(const String & name,bool defaultLog,bool debuggerOutput,bool suppressFileOutput)59 Log* LogManager::createLog( const String& name, bool defaultLog, bool debuggerOutput, 60 bool suppressFileOutput) 61 { 62 OGRE_LOCK_AUTO_MUTEX; 63 64 Log* newLog = OGRE_NEW Log(name, debuggerOutput, suppressFileOutput); 65 66 if( !mDefaultLog || defaultLog ) 67 { 68 mDefaultLog = newLog; 69 } 70 71 mLogs.insert( LogList::value_type( name, newLog ) ); 72 73 return newLog; 74 } 75 //----------------------------------------------------------------------- getDefaultLog()76 Log* LogManager::getDefaultLog() 77 { 78 OGRE_LOCK_AUTO_MUTEX; 79 return mDefaultLog; 80 } 81 //----------------------------------------------------------------------- setDefaultLog(Log * newLog)82 Log* LogManager::setDefaultLog(Log* newLog) 83 { 84 OGRE_LOCK_AUTO_MUTEX; 85 Log* oldLog = mDefaultLog; 86 mDefaultLog = newLog; 87 return oldLog; 88 } 89 //----------------------------------------------------------------------- getLog(const String & name)90 Log* LogManager::getLog( const String& name) 91 { 92 OGRE_LOCK_AUTO_MUTEX; 93 LogList::iterator i = mLogs.find(name); 94 if (i != mLogs.end()) 95 return i->second; 96 else 97 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Log not found. ", "LogManager::getLog"); 98 99 100 } 101 //----------------------------------------------------------------------- destroyLog(const String & name)102 void LogManager::destroyLog(const String& name) 103 { 104 LogList::iterator i = mLogs.find(name); 105 if (i != mLogs.end()) 106 { 107 if (mDefaultLog == i->second) 108 { 109 mDefaultLog = 0; 110 } 111 OGRE_DELETE i->second; 112 mLogs.erase(i); 113 } 114 115 // Set another default log if this one removed 116 if (!mDefaultLog && !mLogs.empty()) 117 { 118 mDefaultLog = mLogs.begin()->second; 119 } 120 } 121 //----------------------------------------------------------------------- destroyLog(Log * log)122 void LogManager::destroyLog(Log* log) 123 { 124 if(!log) 125 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Cannot destroy a null log.", "LogManager::destroyLog"); 126 127 destroyLog(log->getName()); 128 } 129 //----------------------------------------------------------------------- logMessage(const String & message,LogMessageLevel lml,bool maskDebug)130 void LogManager::logMessage( const String& message, LogMessageLevel lml, bool maskDebug) 131 { 132 OGRE_LOCK_AUTO_MUTEX; 133 if (mDefaultLog) 134 { 135 mDefaultLog->logMessage(message, lml, maskDebug); 136 } 137 } 138 logError(const String & message,bool maskDebug)139 void LogManager::logError(const String& message, bool maskDebug ) 140 { 141 stream(LML_CRITICAL, maskDebug) << "Error: " << message; 142 } 143 logWarning(const String & message,bool maskDebug)144 void LogManager::logWarning(const String& message, bool maskDebug ) 145 { 146 stream(LML_WARNING, maskDebug) << "Warning: " << message; 147 } 148 //----------------------------------------------------------------------- setLogDetail(LoggingLevel ll)149 void LogManager::setLogDetail(LoggingLevel ll) 150 { 151 OGRE_LOCK_AUTO_MUTEX; 152 if (mDefaultLog) 153 { 154 mDefaultLog->setLogDetail(ll); 155 } 156 } 157 //--------------------------------------------------------------------- stream(LogMessageLevel lml,bool maskDebug)158 Log::Stream LogManager::stream(LogMessageLevel lml, bool maskDebug) 159 { 160 OGRE_LOCK_AUTO_MUTEX; 161 if (mDefaultLog) 162 return mDefaultLog->stream(lml, maskDebug); 163 else 164 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Default log not found. ", "LogManager::stream"); 165 166 } 167 } 168