Changeset 149
- Timestamp:
- 05/15/09 12:30:27 (3 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
avango-build/src/avango/build/__init__.py (modified) (1 diff)
-
avango-core/SConscript (modified) (1 diff)
-
avango-core/include/avango/Config.h.in (modified) (1 diff)
-
avango-core/include/avango/logging/Logger.h (modified) (5 diffs)
-
avango-core/src/avango/logging/Logger.cpp (modified) (4 diffs)
-
avango-core/src/avango/logging/tests/TestLogging.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/avango-build/src/avango/build/__init__.py
r136 r149 148 148 scons.BoolOption('DEBUG', 'Debug build option', False), 149 149 scons.BoolOption('TRACE_LOGGING', 'Enable/Disable trace log level', False), 150 scons.EnumOption('LOG_LEVEL', 'Support for higher log levels will be compiled out', "DEBUG", 151 ("FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE")), 150 152 scons.PathOption('BINARY_PATH', 151 153 'Additional binary search paths', -
trunk/avango-core/SConscript
r1 r149 33 33 'PREFIX': avango.build.get_prefix().abspath, 34 34 'AVANGO_DEBUG': int(local_env['DEBUG']), 35 'AVANGO_LOG_LEVEL': local_env['LOG_LEVEL'], 35 36 'AVANGO_DISTRIBUTION_SUPPORT': int(local_env['DISTRIBUTION_SUPPORT']), 36 37 'PKG_CONFIG_REQUIRES': '', -
trunk/avango-core/include/avango/Config.h.in
r1 r149 38 38 #endif 39 39 40 #define AVANGO_LOG_LEVEL av::logging::%(AVANGO_LOG_LEVEL)s 41 40 42 #if %(AVANGO_DISTRIBUTION_SUPPORT)s 41 43 #define AVANGO_DISTRIBUTION_SUPPORT 1 -
trunk/avango-core/include/avango/logging/Logger.h
r1 r149 45 45 46 46 #include <avango/Assert.h> 47 #include <avango/Config.h> 47 48 #include <avango/logging/Level.h> 48 49 #include <avango/logging/LoggerManager.h> … … 243 244 * Returns the name of this logger. 244 245 */ 245 AV_DLL const std::string& getName() ;246 AV_DLL const std::string& getName() const; 246 247 247 248 /** 248 249 * Returns true if the logger has a parent logger. 249 250 */ 250 AV_DLL bool hasParent() ;251 AV_DLL bool hasParent() const; 251 252 252 253 /** … … 257 258 258 259 /** 260 * Returns the parent logger of this logger. 261 * \throw std::logic_error If the logger has no parents (which means it is the root logger). 262 */ 263 AV_DLL const Logger& getParent() const; 264 265 /** 259 266 * Get level of this logger. Only messages >= this level are logged 260 267 */ 261 AV_DLL Level getLevel() ;268 AV_DLL Level getLevel() const; 262 269 263 270 /** … … 294 301 */ 295 302 AV_DLL void removeAllAppenders(); 303 304 /** 305 * Check if this logger (or one of its parents) has at least one appender 306 */ 307 AV_DLL bool isActive(Level level) const; 296 308 297 309 /** … … 405 417 #endif 406 418 419 #define AVANGO_LOG(logger, level, message)\ 420 if ((level <= AVANGO_LOG_LEVEL) && (logger.isActive(level)))\ 421 logger.log(level, message); 422 407 423 #endif // #if !defined(AVANGO_LOGGING_LOGGER_H) -
trunk/avango-core/src/avango/logging/Logger.cpp
r1 r149 160 160 161 161 const std::string& 162 av::logging::Logger::getName() 162 av::logging::Logger::getName() const 163 163 { 164 164 return mName; … … 166 166 167 167 bool 168 av::logging::Logger::hasParent() 168 av::logging::Logger::hasParent() const 169 169 { 170 170 return mParent; 171 171 } 172 172 173 av::logging::Logger&174 av::logging::Logger::getParent() 173 const av::logging::Logger& 174 av::logging::Logger::getParent() const 175 175 { 176 176 if (mParent) … … 186 186 } 187 187 188 av::logging::Logger& 189 av::logging::Logger::getParent() 190 { 191 if (mParent) 192 { 193 return *mParent; 194 } 195 else 196 { 197 AV_ASSERT(this == &getRootLogger()); 198 throw std::logic_error("av::logging::Logger::getParent: Logger has no parent."); 199 return *this; 200 } 201 } 202 188 203 av::logging::Level 189 av::logging::Logger::getLevel() 204 av::logging::Logger::getLevel() const 190 205 { 191 206 return mLevel; … … 229 244 boost::mutex::scoped_lock lock(mAppenderMutex); 230 245 mAppenders.clear(); 246 } 247 248 bool 249 av::logging::Logger::isActive(Level level) const 250 { 251 return ( (!mAppenders.empty() && level <= mLevel) || getParent().isActive(level)); 231 252 } 232 253 -
trunk/avango-core/src/avango/logging/tests/TestLogging.cpp
r1 r149 192 192 } 193 193 194 TEST(isActive) 195 { 196 av::Logger& child = av::Logger::getLogger("useLoggerHierarchy::Node"); 197 av::Logger& parent = av::Logger::getLogger("useLoggerHierarchy"); 198 199 boost::shared_ptr<av::logging::Appender> file_app(new av::logging::FileAppender(filename)); 200 parent.addAppender(file_app); 201 202 parent.setLevel(av::logging::ERROR); 203 child.setLevel(av::logging::FATAL); 204 205 CHECK(child.isActive(av::logging::ERROR)); 206 } 207 208 TEST(LOGMacroSuccessfulLogging) 209 { 210 av::Logger& logger = av::Logger::getLogger("useLoggerHierarchy"); 211 std::ostringstream os; 212 boost::shared_ptr<av::logging::Appender> stream_app(new av::logging::StreamAppender(os)); 213 logger.addAppender(stream_app); 214 logger.setLevel(av::logging::ERROR); 215 216 AVANGO_LOG(logger, av::logging::ERROR, "Test"); 217 218 CHECK(!os.str().empty()); 219 } 220 221 TEST(LOGMacroUnsuccessfulLogging) 222 { 223 av::Logger& logger = av::Logger::getLogger("useLoggerHierarchy"); 224 std::ostringstream os; 225 boost::shared_ptr<av::logging::Appender> stream_app(new av::logging::StreamAppender(os)); 226 logger.addAppender(stream_app); 227 logger.setLevel(av::logging::ERROR); 228 229 AVANGO_LOG(logger, av::logging::WARN, "Test"); 230 231 CHECK(os.str().empty()); 232 } 233 194 234 } // namespace 195 235 … … 198 238 int main() 199 239 { 200 //av::getRootLogger().addConsoleAppender();201 240 return UnitTest::RunAllTests(); 202 241 }
Note: See TracChangeset
for help on using the changeset viewer.
