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-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreStableHeaders.h" |
---|
30 | |
---|
31 | #include "OgreLog.h" |
---|
32 | #include "OgreLogManager.h" |
---|
33 | #include "OgreString.h" |
---|
34 | |
---|
35 | namespace Ogre |
---|
36 | { |
---|
37 | |
---|
38 | //----------------------------------------------------------------------- |
---|
39 | Log::Log( const String& name, bool debuggerOuput, bool suppressFile ) : |
---|
40 | mLogLevel(LL_NORMAL), mDebugOut(debuggerOuput), |
---|
41 | mSuppressFile(suppressFile), mLogName(name) |
---|
42 | { |
---|
43 | if (!mSuppressFile) |
---|
44 | { |
---|
45 | mfpLog.open(name.c_str()); |
---|
46 | } |
---|
47 | } |
---|
48 | //----------------------------------------------------------------------- |
---|
49 | Log::~Log() |
---|
50 | { |
---|
51 | OGRE_LOCK_AUTO_MUTEX |
---|
52 | if (!mSuppressFile) |
---|
53 | { |
---|
54 | mfpLog.close(); |
---|
55 | } |
---|
56 | } |
---|
57 | //----------------------------------------------------------------------- |
---|
58 | void Log::logMessage( const String& message, LogMessageLevel lml, bool maskDebug ) |
---|
59 | { |
---|
60 | OGRE_LOCK_AUTO_MUTEX |
---|
61 | if ((mLogLevel + lml) >= OGRE_LOG_THRESHOLD) |
---|
62 | { |
---|
63 | for( mtLogListener::iterator i = mListeners.begin(); i != mListeners.end(); ++i ) |
---|
64 | (*i)->messageLogged( message, lml, maskDebug, mLogName ); |
---|
65 | |
---|
66 | if (mDebugOut && !maskDebug) |
---|
67 | std::cerr << message << std::endl; |
---|
68 | |
---|
69 | // Write time into log |
---|
70 | if (!mSuppressFile) |
---|
71 | { |
---|
72 | struct tm *pTime; |
---|
73 | time_t ctTime; time(&ctTime); |
---|
74 | pTime = localtime( &ctTime ); |
---|
75 | mfpLog << std::setw(2) << std::setfill('0') << pTime->tm_hour |
---|
76 | << ":" << std::setw(2) << std::setfill('0') << pTime->tm_min |
---|
77 | << ":" << std::setw(2) << std::setfill('0') << pTime->tm_sec |
---|
78 | << ": " << message << std::endl; |
---|
79 | |
---|
80 | // Flush stcmdream to ensure it is written (incase of a crash, we need log to be up to date) |
---|
81 | mfpLog.flush(); |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | //----------------------------------------------------------------------- |
---|
87 | void Log::setLogDetail(LoggingLevel ll) |
---|
88 | { |
---|
89 | OGRE_LOCK_AUTO_MUTEX |
---|
90 | mLogLevel = ll; |
---|
91 | } |
---|
92 | |
---|
93 | //----------------------------------------------------------------------- |
---|
94 | void Log::addListener(LogListener* listener) |
---|
95 | { |
---|
96 | OGRE_LOCK_AUTO_MUTEX |
---|
97 | mListeners.push_back(listener); |
---|
98 | } |
---|
99 | |
---|
100 | //----------------------------------------------------------------------- |
---|
101 | void Log::removeListener(LogListener* listener) |
---|
102 | { |
---|
103 | OGRE_LOCK_AUTO_MUTEX |
---|
104 | mListeners.erase(std::find(mListeners.begin(), mListeners.end(), listener)); |
---|
105 | } |
---|
106 | } |
---|