source: OGRE/trunk/ogrenew/OgreMain/src/OgreLogManager.cpp @ 692

Revision 692, 4.6 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26
27#include "OgreLogManager.h"
28#include "OgreException.h"
29#include <algorithm>
30namespace Ogre {
31
32    //-----------------------------------------------------------------------
33    template<> LogManager* Singleton<LogManager>::ms_Singleton = 0;
34    LogManager* LogManager::getSingletonPtr(void)
35    {
36        return ms_Singleton;
37    }
38    LogManager& LogManager::getSingleton(void)
39    { 
40        assert( ms_Singleton );  return ( *ms_Singleton ); 
41    }
42    //-----------------------------------------------------------------------
43    LogManager::LogManager()
44    {
45        mDefaultLog = NULL;
46    }
47    //-----------------------------------------------------------------------
48    LogManager::~LogManager()
49    {
50        // Destroy all logs
51        LogList::iterator i;
52        for (i = mLogs.begin(); i != mLogs.end(); ++i)
53        {
54            delete i->second;
55        }
56    }
57    //-----------------------------------------------------------------------
58    Log* LogManager::createLog( const String& name, bool defaultLog, bool debuggerOutput,
59                bool suppressFileOutput)
60    {
61        Log* newLog = new Log(name, debuggerOutput, suppressFileOutput);
62
63        if( !mDefaultLog || defaultLog )
64        {
65            mDefaultLog = newLog;
66        }
67
68        mLogs.insert( LogList::value_type( name, newLog ) );
69
70        return newLog;
71    }
72    //-----------------------------------------------------------------------
73    Log* LogManager::getDefaultLog()
74    {
75        return mDefaultLog;
76    }
77    //-----------------------------------------------------------------------
78    Log* LogManager::setDefaultLog(Log* newLog)
79    {
80        Log* oldLog = mDefaultLog;
81        mDefaultLog = newLog;
82        return oldLog;
83    }
84    //-----------------------------------------------------------------------
85    Log* LogManager::getLog( const String& name)
86    {
87        LogList::iterator i = mLogs.find(name);
88        if (i != mLogs.end())
89            return i->second;
90        else
91            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Log not found. ", "LogManager::getLog");
92
93
94    }
95    //-----------------------------------------------------------------------
96    void LogManager::logMessage( const String& message, LogMessageLevel lml, bool maskDebug)
97    {
98                if (mDefaultLog)
99                {
100                        mDefaultLog->logMessage(message, lml, maskDebug);
101                }
102    }
103    //-----------------------------------------------------------------------
104    void LogManager::setLogDetail(LoggingLevel ll)
105    {
106                if (mDefaultLog)
107                {
108                mDefaultLog->setLogDetail(ll);
109                }
110    }
111        //-----------------------------------------------------------------------
112        void LogManager::_routeMessage( const String& name,
113                                                                        const String& message,
114                                                                        LogMessageLevel lml,
115                                                                        bool maskDebug )
116        {
117                // Reroute the messages.
118                for( size_t i = 0; i < mListeners.size(); i++ )
119                {
120                        mListeners[i]->write( name,message,lml,maskDebug );
121                }
122        }
123        //-----------------------------------------------------------------------
124        void LogManager::addListener( LogListener * listener )
125        {
126                mListeners.push_back( listener );
127        }
128
129        //-----------------------------------------------------------------------
130        void LogManager::removeListener( LogListener * listener )
131        {
132                mListeners.erase(std::find(mListeners.begin(),
133                        mListeners.end(),
134                        listener));
135        }
136        //-----------------------------------------------------------------------
137        LogListener::~LogListener()
138        {
139        }
140}
Note: See TracBrowser for help on using the repository browser.