Skip to content

Commit d7b08ed

Browse files
[doc] Improve documentation on logger and real-time-logger
Mostly give a sample on how to use the logger member inside the entities.
1 parent 4925f7f commit d7b08ed

File tree

3 files changed

+99
-4
lines changed

3 files changed

+99
-4
lines changed

doc/additionalDoc/debug-doc.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
\page debug Debugging
33
44
They are several ways to perform debugging in dynamic-graph depending on your needs or situation:
5+
- Programmatically inside the entity in C++ will write inside a buffer in a different thread and output in a stream
6+
(either std::cout or a file). It is detailed in \subpage subp_debug_rt_logger.
7+
- Programmatically inside the entity in C++ using a member of the entities and the previous real-time mechanism.
8+
It provides 4 levels of messags :(DEBUG,INFO, WARNING, ERROR). It is described in details here:
9+
\subpage subp_logger
10+
- Programmatically in C++ to avoid overhead with macros and handling level as an int: \subpage subp_dbg_trace
511
- If you just need to collect informations from signals (like rosbag). You can use
6-
an entity called Tracer inside the graph:\subpage tracerdoc
7-
- programmatically in C++ with macros \subpage subp_dbg_trace
8-
- programmatically inside the entity in C++ using member of the entities:
9-
\subpage tracerrealtimedoc
12+
an entity called Tracer inside the graph:\subpage tracerdoc . <br>
13+
A real time version exists
14+
to write directly inside a memory buffer \subpage tracerrealtimedoc
1015
**/

doc/additionalDoc/debug-logger.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
\page subp_logger Loggers
3+
4+
\section sec_logger Initialization of the logger
5+
6+
\subsection subsec_logger_hcpp Header and preprocessor variable
7+
8+
In order to activate the logger you need to add the following lines:
9+
\code
10+
#define ENABLE_RT_LOG
11+
#include <dynamic-graph/real-time-logger.h>
12+
#include <dynamic-graph/logger.h>
13+
\endcode
14+
15+
\subsection subsec_logger_ Initialize the output stream
16+
17+
It is possible to set the output stream of the messages inside a file:
18+
\code
19+
dynamicgraph::RealTimeLogger::instance();
20+
of.open("/tmp/dg-LOGS.txt",std::ofstream::out|std::ofstream::app);
21+
dgADD_OSTREAM_TO_RTLOG (of);
22+
23+
dynamicgraph::RealTimeLogger::destroy();
24+
\endcode
25+
Here the file is "/tmp/dg-LOGS.txt".
26+
27+
\subsection subsec_logger_init Initialization of the logger
28+
29+
Inside the constructor of the entity:
30+
\code
31+
logger_.setTimeSample(0.001);
32+
logger_.setStreamPrintPeriod(0.005);
33+
logger_.setVerbosity(VERBOSITY_ALL);
34+
LoggerVerbosity alv = logger_.getVerbosity();
35+
\endcode
36+
37+
The first line sets the frequency at which the logger will be updated.<br>
38+
The second line specifies at which frequency the message should be
39+
printed.<br>
40+
The third line specifies the level of message to accept.<br>
41+
The fourth line returns the level of verbosity.
42+
In this case, all messages are accepted. <br>
43+
44+
The full list of options are:
45+
<ul>
46+
<li>VERBOSITY_ALL: Accept all messages</li>
47+
<li>VERBOSITY_INFO_WARNING_ERROR: Accept messages at minimum level : INFO, WARNING, ERROR</li>
48+
<li>VERBOSITY_WARNING_ERROR: Accept messages at minimum level : WARNING, ERROR</li>
49+
<li>VERBOSITY_ERROR: Accept messages at minimum level : ERROR</li>
50+
</ul>
51+
52+
53+
\section sec_logger_tests Displaying messages
54+
55+
Here is some example on how to display or record some information.
56+
\code
57+
sendMsg("This is a message of level MSG_TYPE_DEBUG",MSG_TYPE_DEBUG);
58+
sendMsg("This is a message of level MSG_TYPE_INFO",MSG_TYPE_INFO);
59+
sendMsg("This is a message of level MSG_TYPE_WARNING",MSG_TYPE_WARNING);
60+
sendMsg("This is a message of level MSG_TYPE_ERROR",MSG_TYPE_ERROR);
61+
sendMsg("This is a message of level MSG_TYPE_DEBUG_STREAM",MSG_TYPE_DEBUG_STREAM);
62+
sendMsg("This is a message of level MSG_TYPE_INFO_STREAM",MSG_TYPE_INFO_STREAM);
63+
sendMsg("This is a message of level MSG_TYPE_WARNING_STREAM",MSG_TYPE_WARNING_STREAM);
64+
sendMsg("This is a message of level MSG_TYPE_ERROR_STREAM",MSG_TYPE_ERROR_STREAM);
65+
66+
logger_.countdown();
67+
\endcode
68+
*/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
\page subp_debug_rt_logger Real-time Logger
3+
4+
It is intended to be used like this:
5+
\code
6+
#define ENABLE_RT_LOG
7+
#include <dynamic-graph/real-time-logger.h>
8+
9+
// Somewhere in the main function of your executable
10+
int main (int argc, char** argv) {
11+
dgADD_OSTREAM_TO_RTLOG (std::cout);
12+
}
13+
14+
// Somewhere in your library
15+
dgRTLOG() << "your message. Prefer to use \n than std::endl."
16+
\endcode
17+
18+
\note Thread safety. This class expects to have:
19+
- only one reader: the one who take the log entries and write them somewhere.
20+
- one writer at a time. Writing to the logs is **never** a blocking
21+
operation. If the resource is busy, the log entry is discarded.
22+
*/

0 commit comments

Comments
 (0)