Difference between revisions of "DEBUGMSG"
From Net-SNMP Wiki
(→DEBUG) |
(→DEBUGMSGTL) |
||
Line 3: | Line 3: | ||
== DEBUGMSGTL == | == DEBUGMSGTL == | ||
− | DEBUGMSGTL(("token", "statement of some kind: %s\n", "with printf arguments")); | + | '''Note the double (( ))s in these statements!''' |
+ | |||
+ | DEBUGMSGTL(("token", "statement of some kind: %s\n", "with printf arguments")); | ||
This actually outputs two lines: | This actually outputs two lines: |
Latest revision as of 14:51, 22 June 2010
If you want to add Debugging output statements to your own code, you can use the following conventions:
DEBUGMSGTL
Note the double (( ))s in these statements!
DEBUGMSGTL(("token", "statement of some kind: %s\n", "with printf arguments"));
This actually outputs two lines:
- A "trace" line showing where in the source it came from (that's what the T stands for)
- Your debugging line (when -Dtoken is turned on)
This should be the most common debugging statement used. It should be used for complete debugging lines.
DEBUGMSG
For creating lines a piece at a time, start with DEBUGMSGTL followed by DEBUGMSG macros until you hit the newline ("\n"). This is a stupid example but shows how it works:
int total = 0; DEBUGMSGTL(("token", "Calculating running total: ")); for(int i = 0; i < 5; i++) { total = total + i; DEBUGMSG(("token", " %d", total)); } DEBUGMSG(("token", "\n"));
DEBUGMSGOID
For printing OIDs you can use the DEBUGOID macro:
oid my_oid[] = { 1, 3, 6, 1} size_t my_oid_len = 4; DEBUGMSGTL(("token", "this is my oid: ")); DEBUGMSGOID(("token", my_oid, my_oid_len)); DEBUGMSG(("token", "\n"));