reference
常用
define in .cc
NS_LOG_COMPONENT_DEFINE ("DcaTxop");
设置显示等级
代码
void LogComponentEnable (char const *name, enum LogLevel level);
void LogComponentEnableAll (enum LogLevel level);
void LogComponentDisable (char const *name, enum LogLevel level);
void LogComponentDisableAll (enum LogLevel level);
- 前缀
LOG_PREFIX_FUNC = 0x80000000, //!< Prefix all trace prints with function.
LOG_PREFIX_TIME = 0x40000000, //!< Prefix all trace prints with simulation time.
LOG_PREFIX_NODE = 0x20000000, //!< Prefix all trace prints with simulation node.
LOG_PREFIX_LEVEL = 0x10000000, //!< Prefix all trace prints with log level (severity).
LOG_PREFIX_ALL = 0xf0000000 //!< All prefixes.
- examples
LogComponentEnable("test", LOG_LEVEL_INFO); //* 会显示该level及以上的
LogComponentEnable("test", LOG_DEBUG); //* 只会显示这个等级的
LogComponentEnable("test", LOG_ERROR|LOG_PREFIX_FUNC); //* 只会显示这个等级的
命令行 (recommended)
// enable all
NS_LOG="*" ./waf --run xxx
// enable specified component and specified level
NS_LOG="test=level_info" ./waf --run xxx
// add prefix
NS_LOG="test=info|prefix_level" ./waf --run xxx
// integrate all
NS_LOG="<log-component>=<option>|<option>...:<log-component>..." ./waf --run xxx
- 或者采用环境变量的方式
export NS_LOG=UdpEchoClientApplication=level_all
./waf --run xxxx
还有啥*, **,***,自己看官网吧…
配合cmdline传参
NS_LOG="*=error:test=debug" ../waf --run "myTopo --recordInterval=0.01"
NS_LOG="*=error:test=debug" ../waf --run myTopo --command-template="gdb --args %s ns3::PointToPointNetDevice::DataRate=10Mbps"
另一种想要结合命令行传参和gdb功能的就是
NS_LOG="*=error:test=debug" ../waf --run myTopo --command-template="gdb --args %s "
# e.g.
NS_LOG="*=error:test=debug" ../waf --run lp_exp1 --command-template="gdb --args %s ns3::PointToPointNetDevice::DataRate=10Mbps trackTM=\"false\" mars=\"true\" TMReadMaxNum=\"2000\" TMRecordMaxNum=\"10000\" recordInterval=\"0.005\" readInterval=\"1\" reportInterval=\"0.073\" openGymPort=\"5561\" "
>>>>>> 这里似乎等号后面不需要加引号...which我后续再check把...
# 进入gdb后
(gdb) run --ns3::PointToPointNetDevice::DataRate=10Mbps
注意事项
- configure的时候不要-d optimized 不然NSLOG就不好使了 …