9#include "ns3/command-line.h"
10#include "ns3/core-module.h"
11#include "ns3/nstime.h"
12#include "ns3/simulator.h"
70#undef NS_LOG_APPEND_CONTEXT
71#define NS_LOG_APPEND_CONTEXT \
72 if (!g_label.empty()) \
74 ns3LogStream << "[" << g_label << "] "; \
113 NS_ASSERT_MSG(
false,
"assertion in the middle of a log line");
115 else if (
g_mode ==
"fatal")
119 else if (
g_mode ==
"throw")
121 throw std::runtime_error(
"uncaught exception in the middle of a log line");
123 else if (
g_mode ==
"abort")
143 NS_LOG_INFO(
"line 1: logged before the interruption");
145 NS_LOG_INFO(
"line 3: logged after the interruption");
149main(
int argc,
char** argv)
157 "How to interrupt the log line: none, assert, fatal, throw or abort",
159 cmd.AddValue(
"nested",
"Log from within the parameter's operator<<", nested);
160 cmd.AddValue(
"time",
"Simulation time, in seconds, at which the lines are logged", time);
161 cmd.AddValue(
"context",
"Node context of the event logging the lines", context);
162 cmd.AddValue(
"label",
"Label appended to every line by NS_LOG_APPEND_CONTEXT",
g_label);
163 cmd.Parse(argc, argv);
Parse command-line arguments.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
static void Run()
Run the simulation.
@ NO_CONTEXT
Flag for events not associated with any particular context.
static void SetResolution(Unit resolution)
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
void LogLines(bool nested, uint32_t count)
Log three lines, the second one interrupted according to the mode.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Time Seconds(double value)
Construct a Time in the indicated unit.
std::string g_mode
How to interrupt the log line: none, assert, fatal, throw or abort.
std::string g_label
The label appended to every line by NS_LOG_APPEND_CONTEXT, when not empty.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
std::ostream & operator<<(std::ostream &os, const Angles &a)
LogLevel
Logging severity classes and levels.
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_ALL
All prefixes.
A parameter whose operator<< optionally logs, then interrupts the program.
bool nested
Whether to log from within operator<<.
bool interrupt
Whether to interrupt the program according to the mode.