00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #include "OgreStableHeaders.h" 00026 00027 #include "OgreLogManager.h" 00028 00029 #include "OgreException.h" 00030 00031 // Required for va_start, va_end and sprintf 00032 #include <stdio.h> 00033 #include <stdarg.h> 00034 00035 namespace Ogre { 00036 00037 //----------------------------------------------------------------------- 00038 template<> LogManager* Singleton<LogManager>::ms_Singleton = 0; 00039 //----------------------------------------------------------------------- 00040 LogManager::LogManager() 00041 { 00042 mDefaultLog = NULL; 00043 } 00044 //----------------------------------------------------------------------- 00045 LogManager::~LogManager() 00046 { 00047 // Destroy all logs 00048 LogList::iterator i; 00049 for (i = mLogs.begin(); i != mLogs.end(); ++i) 00050 { 00051 delete i->second; 00052 } 00053 } 00054 //----------------------------------------------------------------------- 00055 Log* LogManager::createLog( const String& name, bool defaultLog, bool debuggerOutput) 00056 { 00057 Log* newLog = new Log(name, debuggerOutput); 00058 00059 if( !mDefaultLog || defaultLog ) 00060 { 00061 mDefaultLog = newLog; 00062 } 00063 00064 mLogs.insert( LogList::value_type( name, newLog ) ); 00065 00066 return newLog; 00067 } 00068 //----------------------------------------------------------------------- 00069 Log* LogManager::getDefaultLog() 00070 { 00071 if (!mDefaultLog) 00072 Except(Exception::ERR_INVALIDPARAMS, "No logs created yet. ", "LogManager::getDefaultLog"); 00073 00074 return mDefaultLog; 00075 } 00076 //----------------------------------------------------------------------- 00077 Log* LogManager::getLog( const String& name) 00078 { 00079 LogList::iterator i = mLogs.find(name); 00080 if (i != mLogs.end()) 00081 return i->second; 00082 else 00083 Except(Exception::ERR_INVALIDPARAMS, "Log not found. ", "LogManager::getLog"); 00084 00085 00086 } 00087 //----------------------------------------------------------------------- 00088 void LogManager::logMessage( const String& message, LogMessageLevel lml) 00089 { 00090 getDefaultLog()->logMessage(message, lml); 00091 } 00092 //----------------------------------------------------------------------- 00093 void LogManager::logMessage( LogMessageLevel lml, const char* szMessage, ... ) 00094 { 00095 static char szBuffer[4097]; 00096 va_list list; 00097 va_start( list, szMessage ); 00098 00099 ::vsnprintf( szBuffer, 4096, szMessage, list ); 00100 getDefaultLog()->logMessage( szBuffer, lml ); 00101 00102 va_end( list ); 00103 } 00104 //----------------------------------------------------------------------- 00105 void LogManager::setLogDetail(LoggingLevel ll) 00106 { 00107 getDefaultLog()->setLogDetail(ll); 00108 } 00109 //----------------------------------------------------------------------- 00110 LogManager& LogManager::getSingleton(void) 00111 { 00112 return Singleton<LogManager>::getSingleton(); 00113 } 00114 }
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:15 2004