Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/src/OgreLogManager.cpp @ 1

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 4.7 KB
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-2006 Torus Knot Software Ltd
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
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreStableHeaders.h"
30
31#include "OgreLogManager.h"
32#include "OgreException.h"
33#include <algorithm>
34namespace Ogre {
35
36    //-----------------------------------------------------------------------
37    template<> LogManager* Singleton<LogManager>::ms_Singleton = 0;
38    LogManager* LogManager::getSingletonPtr(void)
39    {
40        return ms_Singleton;
41    }
42    LogManager& LogManager::getSingleton(void)
43    { 
44        assert( ms_Singleton );  return ( *ms_Singleton ); 
45    }
46    //-----------------------------------------------------------------------
47    LogManager::LogManager()
48    {
49        mDefaultLog = NULL;
50    }
51    //-----------------------------------------------------------------------
52    LogManager::~LogManager()
53    {
54                OGRE_LOCK_AUTO_MUTEX
55        // Destroy all logs
56        LogList::iterator i;
57        for (i = mLogs.begin(); i != mLogs.end(); ++i)
58        {
59            delete i->second;
60        }
61    }
62    //-----------------------------------------------------------------------
63    Log* LogManager::createLog( const String& name, bool defaultLog, bool debuggerOutput, 
64                bool suppressFileOutput)
65    {
66                OGRE_LOCK_AUTO_MUTEX
67
68        Log* newLog = new Log(name, debuggerOutput, suppressFileOutput);
69
70        if( !mDefaultLog || defaultLog )
71        {
72            mDefaultLog = newLog;
73        }
74
75        mLogs.insert( LogList::value_type( name, newLog ) );
76
77        return newLog;
78    }
79    //-----------------------------------------------------------------------
80    Log* LogManager::getDefaultLog()
81    {
82                OGRE_LOCK_AUTO_MUTEX
83        return mDefaultLog;
84    }
85    //-----------------------------------------------------------------------
86    Log* LogManager::setDefaultLog(Log* newLog)
87    {
88                OGRE_LOCK_AUTO_MUTEX
89        Log* oldLog = mDefaultLog;
90        mDefaultLog = newLog;
91        return oldLog;
92    }
93    //-----------------------------------------------------------------------
94    Log* LogManager::getLog( const String& name)
95    {
96                OGRE_LOCK_AUTO_MUTEX
97        LogList::iterator i = mLogs.find(name);
98        if (i != mLogs.end())
99            return i->second;
100        else
101            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Log not found. ", "LogManager::getLog");
102
103
104    }
105        //-----------------------------------------------------------------------
106        void LogManager::destroyLog(const String& name)
107        {
108                LogList::iterator i = mLogs.find(name);
109                if (i != mLogs.end())
110                {
111                        if (mDefaultLog == i->second)
112                        {
113                                mDefaultLog = 0;
114                        }
115                        delete i->second;
116                        mLogs.erase(i);
117                }
118
119                // Set another default log if this one removed
120                if (!mDefaultLog && !mLogs.empty())
121                {
122                        mDefaultLog = mLogs.begin()->second;
123                }
124        }
125        //-----------------------------------------------------------------------
126        void LogManager::destroyLog(Log* log)
127        {
128                destroyLog(log->getName());
129        }
130    //-----------------------------------------------------------------------
131    void LogManager::logMessage( const String& message, LogMessageLevel lml, bool maskDebug)
132    {
133                OGRE_LOCK_AUTO_MUTEX
134                if (mDefaultLog)
135                {
136                        mDefaultLog->logMessage(message, lml, maskDebug);
137                }
138    }
139    //-----------------------------------------------------------------------
140    void LogManager::setLogDetail(LoggingLevel ll)
141    {
142                OGRE_LOCK_AUTO_MUTEX
143                if (mDefaultLog)
144                {
145                mDefaultLog->setLogDetail(ll);
146                }
147    }
148}
Note: See TracBrowser for help on using the repository browser.