/src/ogre/OgreMain/src/OgreLogManager.cpp
Line | Count | Source |
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; |
34 | | LogManager* LogManager::getSingletonPtr(void) |
35 | 1 | { |
36 | 1 | return msSingleton; |
37 | 1 | } |
38 | | LogManager& LogManager::getSingleton(void) |
39 | 14.7k | { |
40 | 14.7k | assert( msSingleton ); return ( *msSingleton ); |
41 | 14.7k | } |
42 | | //----------------------------------------------------------------------- |
43 | | LogManager::LogManager() |
44 | 1 | { |
45 | 1 | mDefaultLog = NULL; |
46 | 1 | } |
47 | | //----------------------------------------------------------------------- |
48 | | LogManager::~LogManager() |
49 | 0 | { |
50 | 0 | OGRE_LOCK_AUTO_MUTEX; |
51 | | // Destroy all logs |
52 | 0 | LogList::iterator i; |
53 | 0 | for (i = mLogs.begin(); i != mLogs.end(); ++i) |
54 | 0 | { |
55 | 0 | OGRE_DELETE i->second; |
56 | 0 | } |
57 | 0 | } |
58 | | //----------------------------------------------------------------------- |
59 | | Log* LogManager::createLog( const String& name, bool defaultLog, bool debuggerOutput, |
60 | | bool suppressFileOutput) |
61 | 1 | { |
62 | 1 | OGRE_LOCK_AUTO_MUTEX; |
63 | | |
64 | 1 | Log* newLog = OGRE_NEW Log(name, debuggerOutput, suppressFileOutput); |
65 | | |
66 | 1 | if( !mDefaultLog || defaultLog ) |
67 | 1 | { |
68 | 1 | mDefaultLog = newLog; |
69 | 1 | } |
70 | | |
71 | 1 | mLogs.emplace(name, newLog); |
72 | | |
73 | 1 | return newLog; |
74 | 1 | } |
75 | | //----------------------------------------------------------------------- |
76 | | Log* LogManager::getDefaultLog() |
77 | 0 | { |
78 | 0 | OGRE_LOCK_AUTO_MUTEX; |
79 | 0 | return mDefaultLog; |
80 | 0 | } |
81 | | //----------------------------------------------------------------------- |
82 | | Log* LogManager::setDefaultLog(Log* newLog) |
83 | 0 | { |
84 | 0 | OGRE_LOCK_AUTO_MUTEX; |
85 | 0 | Log* oldLog = mDefaultLog; |
86 | 0 | mDefaultLog = newLog; |
87 | 0 | return oldLog; |
88 | 0 | } |
89 | | //----------------------------------------------------------------------- |
90 | | Log* LogManager::getLog( const String& name) |
91 | 0 | { |
92 | 0 | OGRE_LOCK_AUTO_MUTEX; |
93 | 0 | LogList::iterator i = mLogs.find(name); |
94 | 0 | OgreAssert(i != mLogs.end(), "Log not found"); |
95 | 0 | return i->second; |
96 | 0 | } |
97 | | //----------------------------------------------------------------------- |
98 | | void LogManager::destroyLog(const String& name) |
99 | 0 | { |
100 | 0 | LogList::iterator i = mLogs.find(name); |
101 | 0 | if (i != mLogs.end()) |
102 | 0 | { |
103 | 0 | if (mDefaultLog == i->second) |
104 | 0 | { |
105 | 0 | mDefaultLog = 0; |
106 | 0 | } |
107 | 0 | OGRE_DELETE i->second; |
108 | 0 | mLogs.erase(i); |
109 | 0 | } |
110 | | |
111 | | // Set another default log if this one removed |
112 | 0 | if (!mDefaultLog && !mLogs.empty()) |
113 | 0 | { |
114 | 0 | mDefaultLog = mLogs.begin()->second; |
115 | 0 | } |
116 | 0 | } |
117 | | //----------------------------------------------------------------------- |
118 | | void LogManager::destroyLog(Log* log) |
119 | 0 | { |
120 | 0 | OgreAssert(log, "Cannot destroy a null log"); |
121 | 0 | destroyLog(log->getName()); |
122 | 0 | } |
123 | | //----------------------------------------------------------------------- |
124 | | void LogManager::logMessage( const String& message, LogMessageLevel lml, bool maskDebug) |
125 | 14.7k | { |
126 | 14.7k | OGRE_LOCK_AUTO_MUTEX; |
127 | 14.7k | if (mDefaultLog) |
128 | 14.7k | { |
129 | 14.7k | mDefaultLog->logMessage(message, lml, maskDebug); |
130 | 14.7k | } |
131 | 14.7k | } |
132 | | |
133 | | void LogManager::logError(const String& message, bool maskDebug ) |
134 | 0 | { |
135 | 0 | stream(LML_CRITICAL, maskDebug) << "Error: " << message; |
136 | 0 | } |
137 | | |
138 | | void LogManager::logWarning(const String& message, bool maskDebug ) |
139 | 0 | { |
140 | 0 | stream(LML_WARNING, maskDebug) << "Warning: " << message; |
141 | 0 | } |
142 | | //----------------------------------------------------------------------- |
143 | | void LogManager::setLogDetail(LoggingLevel ll) |
144 | 0 | { |
145 | 0 | OGRE_LOCK_AUTO_MUTEX; |
146 | 0 | if (mDefaultLog) |
147 | 0 | { |
148 | 0 | OGRE_IGNORE_DEPRECATED_BEGIN |
149 | 0 | mDefaultLog->setLogDetail(ll); |
150 | 0 | OGRE_IGNORE_DEPRECATED_END |
151 | 0 | } |
152 | 0 | } |
153 | | //----------------------------------------------------------------------- |
154 | | void LogManager::setMinLogLevel(LogMessageLevel lml) |
155 | 1 | { |
156 | 1 | OGRE_LOCK_AUTO_MUTEX; |
157 | 1 | if (mDefaultLog) |
158 | 1 | { |
159 | 1 | mDefaultLog->setMinLogLevel(lml); |
160 | 1 | } |
161 | 1 | } |
162 | | //--------------------------------------------------------------------- |
163 | | Log::Stream LogManager::stream(LogMessageLevel lml, bool maskDebug) |
164 | 0 | { |
165 | 0 | OGRE_LOCK_AUTO_MUTEX; |
166 | 0 | OgreAssert(mDefaultLog, "Default log not found"); |
167 | 0 | return mDefaultLog->stream(lml, maskDebug); |
168 | 0 | } |
169 | | } |