00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : Logger 00006 * Package : Zeus.ZeusBase.System 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef LoggerH 00033 #define LoggerH 00034 00035 #include <zeusbase/System/Interfaces/IZUnknown.hpp> 00036 #include <zeusbase/System/Interfaces/ILogger.hpp> 00037 #include <zeusbase/System/String.h> 00038 #include <zeusbase/System/AutoPtr.hpp> 00039 #include <zeusbase/System/AtomicInt.hpp> 00040 00041 00042 BEGIN_NAMESPACE_Zeus 00043 00044 #define LOGMODE_DEBUG 0 00045 #define LOGMODE_INFO 1 00046 #define LOGMODE_WARN 2 00047 #define LOGMODE_ERROR 3 00048 #define LOGMODE_FATAL 4 00049 00050 /***************************************************************************/ 00053 /***************************************************************************/ 00054 zeusbase_class TLogger : public TAutoPtr<ILogger> 00055 { 00056 public: 00057 TLogger(); 00058 TLogger(ILogger* pObj); 00059 virtual ~TLogger(); 00060 00061 //Methods to print a debug out 00062 void print (Uint uiMode, const char* pTxt, ...); 00063 void println (Uint uiMode, const char* pTxt, ...); 00064 void printf (Uint uiMode, const char* pTxt, ...); 00065 void printfln(Uint uiMode, const char* pTxt, ...); 00066 00067 void out(const char* pTxt, ...); 00068 00069 //Methods to control offset 00070 void resetOffset(); 00071 void setOffset(Int iValue); 00072 void indent(); 00073 void unindent(); 00074 00075 private: 00077 TAtomicInt m_iOffset; 00078 }; 00079 00080 /***************************************************************************/ 00083 /***************************************************************************/ 00084 inline TLogger::TLogger() : TAutoPtr<ILogger>(NULL) 00085 { 00086 m_iOffset = 0; 00087 } 00088 00089 /***************************************************************************/ 00092 /***************************************************************************/ 00093 inline TLogger::TLogger(ILogger* obj) : TAutoPtr<ILogger>(obj) 00094 { 00095 m_iOffset = 0; 00096 } 00097 00098 00099 /***************************************************************************/ 00102 /***************************************************************************/ 00103 inline TLogger::~TLogger() 00104 {} 00105 00106 /***************************************************************************/ 00109 /***************************************************************************/ 00110 inline void TLogger::resetOffset() 00111 { 00112 m_iOffset = 0; 00113 } 00114 00115 00116 /***************************************************************************/ 00119 /***************************************************************************/ 00120 inline void TLogger::setOffset(Int iValue) 00121 { 00122 m_iOffset = iValue; 00123 } 00124 00125 /***************************************************************************/ 00128 /***************************************************************************/ 00129 inline void TLogger::indent() 00130 { 00131 m_iOffset++; 00132 } 00133 00134 00135 /***************************************************************************/ 00138 /***************************************************************************/ 00139 inline void TLogger::unindent() 00140 { 00141 m_iOffset--; 00142 if (m_iOffset < 0) 00143 { 00144 m_iOffset = 0; 00145 } 00146 } 00147 00148 END_NAMESPACE_Zeus 00149 00150 #endif