# OgreLog.h

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 (c) 2000-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028
    00029 #ifndef __Log_H__
    00030 #define __Log_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreString.h"
    00034
    00035 namespace Ogre {
    00036
    00043     // LogMessageLevel + LoggingLevel > OGRE_LOG_THRESHOLD = message logged
    00044     #define OGRE_LOG_THRESHOLD 4
    00045
    00048     enum LoggingLevel
    00049     {
    00050         LL_LOW = 1,
    00051         LL_NORMAL = 2,
    00052         LL_BOREME = 3
    00053     };
    00054
    00057     enum LogMessageLevel
    00058     {
    00059         LML_TRIVIAL = 1,
    00060         LML_NORMAL = 2,
    00061         LML_CRITICAL = 3
    00062     };
    00063
    00065     class LogListener
    00066     {
    00067     public:
    00068         virtual ~LogListener() {}
    00069
    00082         virtual void messageLogged( const String& message, LogMessageLevel lml, bool maskDebug, const String &logName ) = 0;
    00083     };
    00084
    00085
    00092     class _OgreExport Log : public LogAlloc
    00093     {
    00094     protected:
    00095         std::ofstream   mfpLog;
    00096         LoggingLevel    mLogLevel;
    00097         bool            mDebugOut;
    00098         bool            mSuppressFile;
    00099         bool            mTimeStamp;
    00100         String          mLogName;
    00101
    00102         typedef vector<LogListener*>::type mtLogListener;
    00103         mtLogListener mListeners;
    00104
    00105     public:
    00106
    00107         class Stream;
    00108
    00109         OGRE_AUTO_MUTEX // public to allow external locking
    00114         Log( const String& name, bool debugOutput = true, bool suppressFileOutput = false);
    00115
    00120         ~Log();
    00121
    00123         const String& getName() const { return mLogName; }
    00125         bool isDebugOutputEnabled() const { return mDebugOut; }
    00127         bool isFileOutputSuppressed() const { return mSuppressFile; }
    00129         bool isTimeStampEnabled() const { return mTimeStamp; }
    00130
    00134         void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL, bool maskDebug = false );
    00135
    00137         Stream stream(LogMessageLevel lml = LML_NORMAL, bool maskDebug = false);
    00138
    00143         void setDebugOutputEnabled(bool debugOutput);
    00148         void setLogDetail(LoggingLevel ll);
    00153         void setTimeStampEnabled(bool timeStamp);
    00156         LoggingLevel getLogDetail() const { return mLogLevel; }
    00163         void addListener(LogListener* listener);
    00164
    00171         void removeListener(LogListener* listener);
    00172
    00191         class _OgrePrivate Stream
    00192         {
    00193         protected:
    00194             Log* mTarget;
    00195             LogMessageLevel mLevel;
    00196             bool mMaskDebug;
    00197             typedef StringUtil::StrStreamType BaseStream;
    00198             BaseStream mCache;
    00199
    00200         public:
    00201
    00203             struct Flush {};
    00204
    00205             Stream(Log* target, LogMessageLevel lml, bool maskDebug)
    00206                 :mTarget(target), mLevel(lml), mMaskDebug(maskDebug)
    00207             {
    00208
    00209             }
    00210             // copy constructor
    00211             Stream(const Stream& rhs)
    00212                 : mTarget(rhs.mTarget), mLevel(rhs.mLevel), mMaskDebug(rhs.mMaskDebug)
    00213             {
    00214                 // explicit copy of stream required, gcc doesn't like implicit
    00215                 mCache.str(rhs.mCache.str());
    00216             }
    00217             ~Stream()
    00218             {
    00219                 // flush on destroy
    00220                 if (mCache.tellp() > 0)
    00221                 {
    00222                     mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
    00223                 }
    00224             }
    00225
    00226             template <typename T>
    00227             Stream& operator<< (const T& v)
    00228             {
    00229                 mCache << v;
    00230                 return *this;
    00231             }
    00232
    00233             Stream& operator<< (const Flush& v)
    00234             {
    00235                                 (void)v;
    00236                 mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
    00237                 mCache.str(StringUtil::BLANK);
    00238                 return *this;
    00239             }
    00240
    00241
    00242         };
    00243
    00244     };
    00247 }
    00248
    00249 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:51