User Manual, Developers Guide and API Documentation

Logger.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #ifndef WNS_LOGGER_LOGGER_HPP
00029 #define WNS_LOGGER_LOGGER_HPP
00030 
00031 #include <WNS/logger/Message.hpp>
00032 #include <WNS/logger/Master.hpp>
00033 #include <WNS/pyconfig/View.hpp>
00034 
00035 /* The two macros defined below shall help using messages and disabling them
00036  * when compiling an optimized version, speak defining WNS_NO_LOGGING. Example on
00037  * how to use these macros (assume you've a Logger called "log" which should be
00038  * a member of your class where you're trying to log something):
00039  *
00040  * MESSAGE_BEGIN(NORMAL, log, specifyAnyVariableNameYouLike, "Foo");
00041  * specifyAnyVariableNameYouLike << "bar";
00042  * MESSAGE_END();
00043  *
00044  * Make sure that the code between MESSAGE_BEGIN and MESSAGE_END is only used
00045  * for creating the message, since it's not evaluated if you define WNS_NO_LOGGING.
00046  */
00047 #ifndef WNS_NO_LOGGING
00048 
00049 #define MESSAGE_BEGIN(L, LOGGER, M, STRINGSTREAM) { const wns::logger::Logger& neverUseThisAsLoggerName = (LOGGER); if((LOGGER).getMaster() != NULL && (LOGGER).getMaster()->isEnabled() && (LOGGER).getLevel() >= wns::logger::L) {\
00050 wns::logger::Message M("", wns::logger::L);\
00051 wns::logger::Message& _neverUseThis = M;\
00052 if ((LOGGER).isShowFunction()==true) {_neverUseThis << __PRETTY_FUNCTION__ << "\n";}\
00053 _neverUseThis << STRINGSTREAM;
00054 
00055 #define MESSAGE_END()  neverUseThisAsLoggerName.send(_neverUseThis);}}
00056 
00057 #define MESSAGE_SINGLE(L, LOGGER, STRINGSTREAM) { if((LOGGER).getMaster() != NULL && (LOGGER).getMaster()->isEnabled() && (LOGGER).getLevel() >= wns::logger::L) {\
00058 wns::logger::Message _neverUseThis("", wns::logger::L);\
00059 if ((LOGGER).isShowFunction()==true) {_neverUseThis << __PRETTY_FUNCTION__ << "\n";}\
00060 _neverUseThis << STRINGSTREAM;\
00061 (LOGGER).send(_neverUseThis);}}
00062 
00063 #else
00064 
00065 #define MESSAGE_BEGIN(L, LOGGER, M, STRINGSTREAM) {if(0) {wns::logger::Message M;
00066 
00067 #define MESSAGE_END() }}
00068 
00069 #define MESSAGE_SINGLE(L, LOGGER, STRINGSTREAM) {}
00070 
00071 #endif
00072 
00073 namespace wns { namespace logger {
00074     class Master;
00075 
00079     enum Level { OFF=0, QUIET=1, NORMAL=2, VERBOSE=3, MAXLEVEL };
00080 
00087     class Logger {
00088         friend class LoggerTest;
00089     public:
00103         Logger(
00104             const std::string& moduleName,
00105             const std::string& loggerName,
00106             logger::Master* master);
00107 
00119         Logger(
00120             const std::string& moduleName,
00121             const std::string& loggerName);
00122 
00131         Logger(
00132             const pyconfig::View& pyConfigView,
00133             logger::Master* master);
00134 
00140         explicit
00141         Logger(const pyconfig::View& pyConfigView);
00142 
00148         explicit
00149         Logger();
00150 
00154         virtual
00155         ~Logger();
00156 
00160         Logger(const Logger& other);
00161 
00165         Logger&
00166         operator=(const Logger& other);
00167 
00171         void
00172         configure(const wns::pyconfig::View& config);
00173 
00182         void
00183         send(const Message& m) const;
00184 
00188         void
00189         switchOn();
00190 
00194         void
00195         switchOff();
00196 
00200         long int
00201         getLevel() const;
00202 
00206         void
00207         setLevel(long int _level);
00208 
00212         const std::string&
00213         getModuleName() const;
00214 
00218         const std::string&
00219         getLoggerName() const;
00220 
00224         Master*
00225         getMaster() const;
00226 
00231         bool
00232         isShowFunction() const;
00233 
00234     protected:
00238         std::string mName;
00239 
00243         std::string lName;
00244 
00248         logger::Master* masterLogger;
00249 
00253         bool enabled;
00254 
00258         long int level;
00259 
00264         bool showFunction;
00265     }; // Logger
00266 } // logger
00267 } // wns
00268 #endif // NOT defined WNS_LOGGER_LOGGER_HPP
00269 
00270 

Generated on Sun May 27 03:31:48 2012 for openWNS by  doxygen 1.5.5