日志函数:
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);
NS_LOG_ERROR(msg);//Log error messages;
NS_LOG_WARN(msg);//Log warning messages;
NS_LOG_DEBUG(msg);//Log relatively rare, ad-hoc debugging messages;
NS_LOG_INFO(msg);//Log informational messages about program progress;
NS_LOG_FUNCTION(parameters);//Log a message describing each function called;
NS_LOG_LOGIC(msg);//Log messages describing logical flow within a function;
NS_LOG_ALL//Log everything.
NS_LOG_UNCOND(msg);//无条件输出
NS_LOG_FUNCTION_NOARGS();
........
用法:
-
int main(int argc,char *argv[])
前:
`定义日志名字(不能重复)`
NS_LOG_COMPONENT_DEFINE ("ASpecialName");
NS_LOG_COMPONENT_DEFINE的定义在文件 .../ns-3.26/src/core/model/log.h
中
- 声明完变量,定义好命令行等一堆需要放在程序开头的东西之后:
`启动日志`
LogComponentEnable ("ASpecialName",LOG_LEVEL_INFO);
- 之后就可以在合适的地方使用其他日志函数了:
一些别的
在函数中插入
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
运行代码,输出:
NAME@ubuntu:~/source/ns-3.26$ ./waf --run scratch/second
Waf: Entering directory `/home/NAME/source/ns-3.26/build'
Waf: Leaving directory `/home/NAME/source/ns-3.26/build'
Build commands will be stored in build/compile_commands.json
'build' finished successfully (1.884s)
At time 2s client sent 1024 bytes to 10.1.2.4 port 9
At time 2.0078s server received 1024 bytes from 10.1.1.1 port 49153
At time 2.0078s server sent 1024 bytes to 10.1.1.1 port 49153
At time 2.01761s client received 1024 bytes from 10.1.2.4 port 9
后四行“sent”和“received”部分来自UdpEchoClientApplication和UdpEchoServerApplication的日志消息。
一个示例
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("AnExample");
int main (int argc, char *argv[])
{
uint32_t AVariate = 3;
CommandLine cmd;
cmd.Parse (argc,argv);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
.......
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
网友评论