diff --git a/src/core/log.cc b/src/core/log.cc index 64a288289..fc7576cfa 100644 --- a/src/core/log.cc +++ b/src/core/log.cc @@ -17,6 +17,9 @@ * * Author: Mathieu Lacage */ + +#ifdef NS3_LOG_ENABLE + #include #include #include @@ -295,4 +298,4 @@ LogComponentPrintList (void) } // namespace ns3 - +#endif // NS3_LOG_ENABLE diff --git a/src/core/log.h b/src/core/log.h index f6e8f45a2..1ab45080d 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -17,8 +17,9 @@ * * Author: Mathieu Lacage */ -#ifndef LOG_H -#define LOG_H + +#ifndef __LOG_H__ +#define __LOG_H__ #include #include @@ -61,9 +62,18 @@ * ns3::LogComponentDisable functions or with the NS_LOG * environment variable. */ + +#ifdef NS3_LOG_ENABLE + #define NS_LOG_COMPONENT_DEFINE(name) \ static ns3::LogComponent g_log = ns3::LogComponent (name) +#else + +#define NS_LOG_COMPONENT_DEFINE(name) + +#endif + /** * \ingroup logging * \param msg message to output @@ -74,15 +84,18 @@ * defined with the NS_LOG_COMPONENT_DEFINE macro in the * same file. */ -#define NS_LOG(level, msg) \ - do \ - { \ - if (g_log.IsEnabled (level)) \ - { \ - std::clog << __PRETTY_FUNCTION__ << " ==> " << \ - msg << std::endl; \ - } \ - } \ + +#ifdef NS3_LOG_ENABLE + +#define NS_LOG(level, msg) \ + do \ + { \ + if (g_log.IsEnabled (level)) \ + { \ + std::clog << __PRETTY_FUNCTION__ << " ==> " << \ + msg << std::endl; \ + } \ + } \ while (false) #define NS_LOG_F(level) \ @@ -95,7 +108,6 @@ } \ while (false) - #define NS_LOG_ERROR(msg) \ NS_LOG(ns3::LOG_LEVEL_ERROR, msg) @@ -127,8 +139,26 @@ } \ while (false) +#else + +#define NS_LOG(level, msg) +#define NS_LOG_F(level) +#define NS_LOG_ERROR(msg) +#define NS_LOG_WARN(msg) +#define NS_LOG_DEBUG(msg) +#define NS_LOG_INFO(msg) +#define NS_LOG_FUNCTION +#define NS_LOG_PARAM(msg) +#define NS_LOG_LOGIC(msg) +#define NS_LOG_ALL(msg) +#define NS_LOG_UNCOND(msg) + +#endif + namespace ns3 { +#ifdef NS3_LOG_ENABLE + enum LogLevel { LOG_LEVEL_ERROR = 1<<0, // serious error messages only LOG_LEVEL_WARN = 1<<1, // add warning messages @@ -140,6 +170,8 @@ enum LogLevel { LOG_LEVEL_ALL = 1<<30 // print everything }; +#endif + /** * \param name a log component name * \ingroup logging @@ -148,7 +180,11 @@ enum LogLevel { * The logging output can be later disabled with a call * to ns3::LogComponentDisable. */ +#ifdef NS3_LOG_ENABLE void LogComponentEnable (char const *name, enum LogLevel level); +#else +#define LogComponentEnable(a,b) +#endif /** * \param name a log component name @@ -158,7 +194,11 @@ void LogComponentEnable (char const *name, enum LogLevel level); * The logging output can be later re-enabled with a call * to ns3::LogComponentEnable. */ +#ifdef NS3_LOG_ENABLE void LogComponentDisable (char const *name, enum LogLevel level); +#else +#define LogComponentDisable(a,b) +#endif /** * \ingroup logging @@ -170,7 +210,13 @@ void LogComponentDisable (char const *name, enum LogLevel level); * * For example: NS_LOG=print-list */ +#ifdef NS3_LOG_ENABLE void LogComponentPrintList (void); +#else +#define LogComponentPrintList() +#endif + +#ifdef NS3_LOG_ENABLE class LogComponent { public: @@ -183,6 +229,8 @@ private: int32_t m_levels; }; +#endif + } // namespace ns3 -#endif /* LOG_H */ +#endif // __LOG_H__ diff --git a/src/node/queue.cc b/src/node/queue.cc index a2eec08ae..4a622c2b0 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -214,7 +214,7 @@ bool Queue::IsEmpty (void) { NS_LOG_FUNCTION; - NS_LOG_LOGIC ("returns" << (m_nPackets == 0)); + NS_LOG_LOGIC ("returns " << (m_nPackets == 0)); return m_nPackets == 0; } diff --git a/tutorial/hello-simulator.cc b/tutorial/hello-simulator.cc index 84ac0914e..735d98130 100644 --- a/tutorial/hello-simulator.cc +++ b/tutorial/hello-simulator.cc @@ -16,10 +16,10 @@ #include "ns3/log.h" -using namespace ns3; - NS_LOG_COMPONENT_DEFINE ("HelloSimulator"); +using namespace ns3; + int main (int argc, char *argv[]) { diff --git a/wscript b/wscript index 9e54f7050..1e8fd84e2 100644 --- a/wscript +++ b/wscript @@ -119,6 +119,7 @@ def configure(conf): if 'debug' in Params.g_options.debug_level.lower(): variant_env.append_value('CXXDEFINES', 'NS3_DEBUG_ENABLE') variant_env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE') + variant_env.append_value('CXXDEFINES', 'NS3_LOG_ENABLE') ## In optimized builds we still want debugging symbols, e.g. for ## profiling, and at least partially usable stack traces.