Logging
Logging is done using the Ros2 Singleton.
Output
To log a message you can use one of the following methods debug, info, warn, error and fatal.
Button {
// ...
onClicked: Ros2.info("Button clicked.")
// or using a named logger
onClicked: Ros2.getLogger("my_logger").info("Button clicked.")
}
This will produce the following output:
[ INFO] [1583062360.048922959] [qml_logging_demo]: Button clicked.
and publish the following on /rosout (unless NoRos2out was specified in the Ros2InitOptions).
header:
seq: 1
stamp:
secs: 1583062360
nsecs: 49001300
frame_id: ''
level: 2
name: "/qml_logging_demo"
msg: "Button clicked."
file: "/home/stefan/qml_ros2_plugin/examples/logging.qml"
function: "onClicked"
line: 130
topics: [/rosout]
The file, function and line info is automatically extracted when you call the log function.
Set Verbosity
You can change the verbosity, i.e., the minimal level of logging message that is printed
(and published if enabled), using Ros2.getLogger().setLoggerLevel.
You can also use Ros2.getLogger() to obtain a named logger instance.
By default the logging level is set to Info.
To enable debug messages you can set it to Debug as follows:
Ros2.getLogger().setLoggerLevel(Ros2LoggerLevel.Debug);
// or
Ros2.getLogger("my_logger").setLoggerLevel(Ros2LoggerLevel.Warn)
The first argument to that method is the name of the console to which the logging is printed.
These are identifiers used by ros to enable you to change the verbosity of a submodule of your node using
rqt_console.
Ros2.getLogger(QString) method.Ros2.init().Possible values for the console level are: Debug, Info, Warn, Error and Fatal.