File: logging.md

package info (click to toggle)
robotraconteur 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,380 kB
  • sloc: cpp: 1,149,268; cs: 87,653; java: 58,127; python: 26,897; ansic: 356; sh: 152; makefile: 90; xml: 51
file content (125 lines) | stat: -rw-r--r-- 4,703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Logging {#logging}

Robot Raconteur version 0.9.3 introduced logging capabilities. 1200+ log points have been inserted into the core library to assist developers using the library. These log points provide detailed insight into the behavior of the library and assist with tracing the location and cause of errors.

Log data is contained in "records" which have the following form:

```
class ROBOTRACONTEUR_CORE_API RRLogRecord
{
public:
    RR_WEAK_PTR<RobotRaconteurNode> Node;
    RobotRaconteur_LogLevel Level;
    RobotRaconteur_LogComponent Component;
    std::string ComponentName;
    std::string ComponentObjectID;
    int64_t Endpoint;
    std::string ServicePath;
    std::string Member;
    std::string Message;
    boost::posix_time::ptime Time;
    std::string SourceFile;
    uint32_t SourceLine;
    std::string ThreadID;
    std::string FiberID;
};
```

The record contains the originating node, the level of the log message, the component the message originated from, the Robot Raconteur endpoint id, the service path, the object member, the timestamp of the message, the source file an line of the log point, and the thread/coroutine fiber.

By default log messages are sent to `stderr`. They can optionally be sent to a file using `FileLogRecordHandler`. The log records have the following default text format, where italic are left out if not specified:

    [Time (as ISO)] [LogLevel] [ThreadID,FiberID] [NodeID] [Component,*ComponentName*,*ComponentObjectID*] [Endpoint,*ServicePath*,*Member*] *[SourceFile,SourceLine]* Message

Log messages can have the following levels:

```
enum RobotRaconteur_LogLevel
{
	RobotRaconteur_LogLevel_Trace, // Used to trace the activity of the node. Disabled in Release builds
	RobotRaconteur_LogLevel_Debug, // Notification of errors or important activity, use to debug unexpected behavior
	RobotRaconteur_LogLevel_Info, // Information about activity that can be logged during normal operation
	RobotRaconteur_LogLevel_Warning, // Warnings of potential errors
	RobotRaconteur_LogLevel_Error, // Notification of non-fatal errors
	RobotRaconteur_LogLevel_Fatal, // Notification of fatal errors that may affect program stability
	RobotRaconteur_LogLevel_Disable=1000 // Disable all logging
};
```

Log levels are set using the `RobotRaconteurNode::SetLogLevel(level)` function. Logging may also be configured using the `RobotRaconteurNode::SetLogLevelFromEnvVariable()` function. This function is called automatically by `NodeSetup`, and by Python and Matlab clients. The environmental variable `ROBOTRACONTEUR_LOG_LEVEL` is used to set the logging level. It can have the following values: `TRACE`, `DEBUG`, 'INFO`, `WARNING`, `ERROR`, `FATAL`. Log levels can also be configured using \ref command_line_options.

For example, on Linux and Mac OSX, enable debug log level using:

    export ROBOTRACONTEUR_LOG_LEVEL=DEBUG

for Windows, use:

    set ROBOTRACONTEUR_LOG_LEVEL=DEBUG

Records are typically created using the `ROBOTRACONTEUR_LOG` macros. These can be found in Logging.h. These macros are named for the log level, and can optionally include component, path, and component name information.

Records are passed to the node using the `RobotRaconteurNode::LogRecord()` function. By default, the result is sent to `stderr`. The function `RobotRaconteurNode::SetLogRecordHandler(handler)` can be used to send the log record to handler. See below for examples.

## Enable Debug Logging Examples

Examples of enabling Debug level logging:

### Env Variable

Linux:

    export ROBOTRACONTEUR_LOG_LEVEL=DEBUG

Windows:

    set ROBOTRACONTEUR_LOG_LEVEL=DEBUG

### C++

    RobotRaconteurNode::s()->SetLogLevel(RobotRaconteur_LogLevel_Debug);

### C#

    RobotRaconteurNode.s.SetLogLevel(LogLevel.LogLevel_Debug);

### Java

    RobotRaconteurNode.s().setLogLevel(LogLevel.LogLevel_Debug);

### Python

    RRN.SetLogLevel(RR.LogLevel_Debug)

### MATLAB

    RobotRaconteur.SetLogLevel('DEBUG')

## Save log to file

### C++

    FileLogRecordHandlerPtr log_handler = RR_MAKE_SHARED<FileLogRecordHandler>();
    log_handler.OpenFile("my_log.txt");
    RobotRaconteurNode::s()->SetLogRecordHandler(log_handler);

### C#

    var log_handler = new FileLogRecordHandler();
    log_handler.OpenFile("my_log.txt");
    RobotRaconteurNode.s.SetLogRecordHandler(log_handler);

### Java

    FileLogRecordHandler log_handler = new FileLogRecordHandler();
    log_handler.openFile("my_log.txt");
    RobotRaconteurNode.s().setLogRecordHandler(log_handler);

### Python

    log_handler = RR.FileLogRecordHandler()
    log_handler.OpenFile("my_log.txt")
    RRN.SetLogRecordHandler(log_handler)

### MATLAB

    RobotRaconteur.OpenLogFile('my_log.txt')