Bug 1496 - Option to print log level in NS_LOG messages
Option to print log level in NS_LOG messages
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: documentation
ns-3-dev
All All
: P5 normal
Assigned To: Tom Henderson
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-08-24 20:27 UTC by Peter Barnes
Modified: 2013-12-12 17:46 UTC (History)
2 users (show)

See Also:


Attachments
diff of src/core/model/log.{h,cc} (4.06 KB, patch)
2012-08-24 20:27 UTC, Peter Barnes
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Barnes 2012-08-24 20:27:53 UTC
Created attachment 1438 [details]
diff of src/core/model/log.{h,cc}

It'd be nice if there was an option to print the LOG_LEVEL (severity) in the message, similar to prefixing the time, node, or function.

This patch enables

NS_LOG="*=all|prefix_level"

and prints as

[ERROR] error message
[WARN] warn message
[DEBUG] debug message
[INFO] info message
[LOGIC] logic message


$ NS_LOG="*=all|prefix_all" ./waf --run scratch-simulator
Scratch Simulator
ScratchSimulator:main(): [ERROR] error message
ScratchSimulator:main(): [WARN] warn message
ScratchSimulator:main(): [DEBUG] debug message
ScratchSimulator:main(): [INFO] info message
ScratchSimulator:main(function)
ScratchSimulator:main(): [LOGIC] logic message

(I added   NS_LOG_ERROR  ("error message"), etc to scratch-simulator.cc, for illustration.)

If this patch is accepted, I volunteer to amend the tutorial.
Comment 1 Peter Barnes 2012-08-24 20:29:17 UTC
Also added "prefix_all", as you'll see in the diff.
Comment 2 Peter Barnes 2012-08-24 20:31:21 UTC
Relabel to core component.
Comment 3 Mathieu Lacage 2012-08-27 03:23:14 UTC
ok for commit. Can you please update this bug report with the commit changeset once you are done ?
Comment 4 Peter Barnes 2012-11-05 15:15:34 UTC
Commit 9c0cc3997ece
http://code.nsnam.org/ns-3-dev/rev/9c0cc3997ece

I volunteered to write a manual chapter, but that's going to have to wait, along with some ideas for wildcards...
Comment 5 Peter Barnes 2012-11-27 22:52:35 UTC
This has been reraised in bug 1531.
Comment 6 Tom Henderson 2012-12-24 10:12:25 UTC
I'm reopening this, as this doesn't seem to behave as expected as of ns-3.16:

NS_LOG="*=all|prefix_all" ./waf --run first

nor this:

NS_LOG="*=all|prefix_all" ./waf --run scratch-simulator

(prefix levels are not printed out)

Also, the scratch-simulator.cc program was not patched as described in the tracker.
Comment 7 Tom Henderson 2012-12-24 10:25:49 UTC
actually, after further testing and reading the patch, it seems to be working since it is limited to these levels:

+  labels[LOG_ERROR]    = "ERROR";
+  labels[LOG_WARN]     = "WARN";
+  labels[LOG_DEBUG]    = "DEBUG";
+  labels[LOG_INFO]     = "INFO";
+  labels[LOG_LOGIC]    = "LOGIC";


but I'll leave this open until documentation is completed.
Comment 8 Peter Barnes 2013-12-12 17:46:41 UTC
Documentation:  commit f70e78d94658