Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreLogManager.cpp

Go to the documentation of this file.

    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     LogManager* LogManager::getSingletonPtr(void)
    00040     {
    00041         return ms_Singleton;
    00042     }
    00043     LogManager& LogManager::getSingleton(void)
    00044     {
    00045         assert( ms_Singleton );  return ( *ms_Singleton );
    00046     }
    00047     //-----------------------------------------------------------------------
    00048     LogManager::LogManager()
    00049     {
    00050         mDefaultLog = NULL;
    00051     }
    00052     //-----------------------------------------------------------------------
    00053     LogManager::~LogManager()
    00054     {
    00055         // Destroy all logs
    00056         LogList::iterator i;
    00057         for (i = mLogs.begin(); i != mLogs.end(); ++i)
    00058         {
    00059             delete i->second;
    00060         }
    00061     }
    00062     //-----------------------------------------------------------------------
    00063     Log* LogManager::createLog( const String& name, bool defaultLog, bool debuggerOutput)
    00064     {
    00065         Log* newLog = new Log(name, debuggerOutput);
    00066
    00067         if( !mDefaultLog || defaultLog )
    00068         {
    00069             mDefaultLog = newLog;
    00070         }
    00071
    00072         mLogs.insert( LogList::value_type( name, newLog ) );
    00073
    00074         return newLog;
    00075     }
    00076     //-----------------------------------------------------------------------
    00077     Log* LogManager::getDefaultLog()
    00078     {
    00079         if (!mDefaultLog)
    00080             Except(Exception::ERR_INVALIDPARAMS, "No logs created yet. ", "LogManager::getDefaultLog");
    00081
    00082         return mDefaultLog;
    00083     }
    00084     //-----------------------------------------------------------------------
    00085     Log* LogManager::setDefaultLog(Log* newLog)
    00086     {
    00087         Log* oldLog = mDefaultLog;
    00088         mDefaultLog = newLog;
    00089         return oldLog;
    00090     }
    00091     //-----------------------------------------------------------------------
    00092     Log* LogManager::getLog( const String& name)
    00093     {
    00094         LogList::iterator i = mLogs.find(name);
    00095         if (i != mLogs.end())
    00096             return i->second;
    00097         else
    00098             Except(Exception::ERR_INVALIDPARAMS, "Log not found. ", "LogManager::getLog");
    00099
    00100
    00101     }
    00102     //-----------------------------------------------------------------------
    00103     void LogManager::logMessage( const String& message, LogMessageLevel lml, bool maskDebug)
    00104     {
    00105         getDefaultLog()->logMessage(message, lml, maskDebug);
    00106     }
    00107     //-----------------------------------------------------------------------
    00108     void LogManager::logMessage( LogMessageLevel lml, const char* szMessage, ... )
    00109     {
    00110         static char szBuffer[4097];
    00111         va_list list;
    00112         va_start( list, szMessage );
    00113
    00114         ::vsnprintf( szBuffer, 4096, szMessage, list );
    00115         getDefaultLog()->logMessage( szBuffer, lml );
    00116
    00117         va_end( list );
    00118     }
    00119     //-----------------------------------------------------------------------
    00120     void LogManager::setLogDetail(LoggingLevel ll)
    00121     {
    00122         getDefaultLog()->setLogDetail(ll);
    00123     }
    00124 }

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:31 2004