![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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 #include <WNS/logger/Logger.hpp> 00029 #include <WNS/logger/Master.hpp> 00030 #include <WNS/simulator/ISimulator.hpp> 00031 00032 using namespace wns::logger; 00033 00034 Logger::Logger( 00035 const std::string& moduleName, 00036 const std::string& loggerName, 00037 logger::Master* m) : 00038 00039 mName(moduleName), 00040 lName(loggerName), 00041 masterLogger(m), 00042 enabled(true), 00043 level(2), 00044 showFunction(false) 00045 { 00046 if(enabled && masterLogger) { 00047 masterLogger->registerLogger(mName, lName); 00048 } 00049 } // Logger 00050 00051 Logger::Logger( 00052 const std::string& moduleName, 00053 const std::string& loggerName) : 00054 00055 mName(moduleName), 00056 lName(loggerName), 00057 masterLogger(wns::simulator::getMasterLogger()), 00058 enabled(true), 00059 level(2), 00060 showFunction(false) 00061 { 00062 if (enabled && masterLogger) 00063 { 00064 masterLogger->registerLogger(mName, lName); 00065 } 00066 } // Logger 00067 00068 Logger::Logger( 00069 const pyconfig::View& pyConfigView, 00070 logger::Master* m) : 00071 00072 mName(pyConfigView.get<std::string>("moduleName")), 00073 lName(pyConfigView.get<std::string>("name")), 00074 masterLogger(m), 00075 enabled(pyConfigView.get<bool>("enabled")), 00076 level(pyConfigView.get<long int>("level")), 00077 showFunction(pyConfigView.get<bool>("showFunction")) 00078 { 00079 if(enabled && masterLogger) { 00080 masterLogger->registerLogger(mName, lName); 00081 } 00082 } // Logger 00083 00084 Logger::Logger(const pyconfig::View& pyConfigView) : 00085 mName(pyConfigView.get<std::string>("moduleName")), 00086 lName(pyConfigView.get<std::string>("name")), 00087 masterLogger(wns::simulator::getMasterLogger()), 00088 enabled(pyConfigView.get<bool>("enabled")), 00089 level(pyConfigView.get<long int>("level")), 00090 showFunction(pyConfigView.get<bool>("showFunction")) 00091 { 00092 if (enabled && masterLogger) 00093 { 00094 masterLogger->registerLogger(mName, lName); 00095 } 00096 } // Logger 00097 00098 Logger::Logger() : 00099 mName("unspecified"), 00100 lName("unspecified"), 00101 masterLogger(wns::simulator::getMasterLogger()), 00102 enabled(false), 00103 level(0) 00104 { 00105 } 00106 00107 Logger::~Logger() 00108 { 00109 } // ~Logger 00110 00111 Logger::Logger(const Logger& other) : 00112 mName(other.mName), 00113 lName(other.lName), 00114 masterLogger(other.masterLogger), // sharing the same instance 00115 enabled(other.enabled), 00116 level(other.level), 00117 showFunction(other.showFunction) 00118 { 00119 } 00120 00121 Logger& 00122 Logger::operator=(const Logger& other) 00123 { 00124 mName = other.mName; 00125 lName = other.lName; 00126 masterLogger = other.masterLogger; // sharing the same instance 00127 enabled = other.enabled; 00128 level = other.level; 00129 showFunction = other.showFunction; 00130 return *this; 00131 } 00132 00133 void 00134 Logger::configure(const wns::pyconfig::View& config) 00135 { 00136 mName = config.get<std::string>("moduleName"); 00137 lName = config.get<std::string>("name"); 00138 enabled = config.get<bool>("enabled"); 00139 level = config.get<long int>("level"); 00140 showFunction = config.get<bool>("showFunction"); 00141 } // configure 00142 00143 void 00144 Logger::switchOn() 00145 { 00146 enabled=true; 00147 } // switchOn 00148 00149 void 00150 Logger::switchOff() 00151 { 00152 enabled=false; 00153 } // switchOff 00154 00155 long int 00156 Logger::getLevel() const 00157 { 00158 return level; 00159 } 00160 00161 void 00162 Logger::setLevel(long int _level) 00163 { 00164 assure(_level >= OFF,"bad level"); 00165 assure(_level < MAXLEVEL,"bad level"); 00166 level = _level; 00167 } 00168 00169 const std::string& 00170 Logger::getModuleName() const 00171 { 00172 return mName; 00173 } 00174 00175 const std::string& 00176 Logger::getLoggerName() const 00177 { 00178 return lName; 00179 } 00180 00181 Master* 00182 Logger::getMaster() const 00183 { 00184 return this->masterLogger; 00185 } 00186 00187 #ifndef WNS_NO_LOGGING 00188 00189 void 00190 Logger::send(const Message& m) const 00191 { 00192 if( enabled && masterLogger && (m.getLevel() <= this->level) ) 00193 { 00194 masterLogger->write(mName, lName, m.getString()); 00195 } 00196 } 00197 00198 #else 00199 00200 void 00201 Logger::send(const Message&) const 00202 { 00203 } 00204 00205 #endif 00206 00207 bool 00208 Logger::isShowFunction() const 00209 { 00210 return showFunction; 00211 00212 } 00213 00214
1.5.5