Log configuration method for Cyclone DDS

We have two ways to Set environment variables before running the program.

  1. XML configuration file: The configuration parameters of Cyclone DDS are defined using an XML file. You can create a custom XML configuration file and specify the location of the configuration file by setting the CYCLONEDDS_URI environment variable.
  • Linux: export CYCLONEDDS_URI=file://$HOME/path/to/dds/configuration.xml
  1. Direct setting of environment variables: You can also directly set the XML configuration to the CYCLONEDDS_URI environment variable without using external files. For example:
  • Linux: export CYCLONEDDS_URI="<CycloneDDS><Domain><General><NetworkInterfaceAddress>127.0.0.1</NetworkInterfaceAddress></General></Domain></CycloneDDS>"

After setting the environment variables, you can verify whether the variables have been set correctly by using the echo $CYCLONEDS_URI command. If everything is normal, the terminal will output the XML configuration you have set.

Please note that the environment variables set using the export command are only valid in the current terminal session. If you open a new terminal window, these variables will not be retained. If you want these variables to be available in all new terminal sessions, you need to add these export commands to your~/. bashrc or~/. profile files.

The logging function of Cyclone DDS: 

Configure Tracing and Verbosity:

Tracing and Verbosity: Cyclone DDS can generate detailed tracking information, including all traffic and internal activities. You can set different tracking levels, for example:

Reporting and tracing — Eclipse Cyclone DDS, 0.11.0

Using Tracing and Verbosity:

According to the set Verbosity level, Cyclone DDS will generate logs with different levels of detail.

For example,

<Tracing>
<Verbosity> finest</Verbosity>
<OutputFile>
        ${HOME}/work_space/log/cyclonedds.log.${CYCLONEDDS_PID}
</OutputFile>
<AppendToFile>true</AppendToFile>

<EnableCategory>fatal,error,config,info</EnableCategory>
</Tracing>

  • In Cyclone DDS, you can set Tracing and Verbosity through an XML configuration file. You need to set relevant child elements in the<Tracing>element.
  • The<Verbosity>element allows you to choose a predefined tracking level, such as none, severe, error, warning, config, info, fine, fine, finest, etc. <Verbosity>is set to finest level provides detailed tracking of all activities, while none does not generate any tracking information.
  • The log file is usually written to the <OutputFile>specified in the configuration. The use of variables like ${CYCLONEDDS_PID} allows for dynamic file naming based on the process ID, making it easier to correlate logs with specific instances of the DDS application.
  • The <enableCategory> element is a comma separated list that allows you to enable individual information categories, such as fatal, error, warning, config, info, discovery, data, timing, traffic, etc.
  • If <AppendToFile>is set to true, it will append content to the existing log file instead of replacing it.
  • The <EnableCategory> element in the Cyclone DDS configuration file specifies which categories of events should be logged. By setting this element, you can filter the types of messages that are recorded in the log files, which helps in diagnosing issues and monitoring the system’s behavior. Here are the functions of the categories mentioned in your configuration.

# The following shows an example XML configuration:

The XML configuration file is for setting up the logging parameters of Cyclone DDS, Here’s a description of the key elements in this configuration:

  • <Domain Id="any">: This specifies that the configuration applies to any DDS domain, which is a logical network partitioning that allows for separate data spaces in DDS applications.
  • <General>: This section contains general settings for the DDS environment.
    • <Interfaces>: Defines the network interfaces that Cyclone DDS will use.
  • <NetworkInterface autodetermine="true" priority="default" multicast="default" />: Cyclone DDS will automatically determine the network interface to use, with default priority and multicast settings.
  • <AllowMulticast>default</AllowMulticast>: This enables or disables the use of multicast for discovery and data distribution, set to the default policy.
  • <MaxMessageSize>65500B</MaxMessageSize>: Sets the maximum size of a message that can be sent or received to 65500 bytes.
  • <Tracing>: This section configures the logging behavior.
    • <Verbosity>config</Verbosity>: Sets the verbosity level of the logs to “config”, which includes configuration-related messages.
    • <OutputFile>: Defines the path and filename pattern for the log files.
      • path/to/log/cyclonedds.log.${CYCLONEDDS_PID}: The logs will be saved in the user’s home directory under “path/to/log”, with the filename including the process ID of the Cyclone DDS instance.
    • <AppendToFile>true</AppendToFile>: Indicates that new log entries will be appended to the existing file rather than overwriting it.
    • <EnableCategory>fatal,error,config,info</EnableCategory>: Specifies the categories of events that will be logged, which include fatal errors, regular errors, configuration messages, and informational messages.

This configuration ensures that Cyclone DDS logs important events and errors to a specified file, which aids in monitoring and debugging the DDS environment. The use of variables like ${CYCLONEDDS_PID} allows for dynamic file naming based on the process ID, making it easier to correlate logs with specific instances of the DDS application.

CycloneDDS/Domain/Tracing3

Children: AppendToFile, Category|EnableCategory, OutputFile, PacketCaptureFile, Verbosity

The Tracing element controls the amount and type of information that is written into the tracing log by the DDSI service. This is useful to track the DDSI service during application development.

The logging and tracing api offered by Cyclone DDS is a merger of the reporting functionality that existed in the various modules that Cyclone is made out of. Why the API needed to change is documented in the section [Issues with previous implementation].

The new and improved logging mechanism in Cyclone DDS allows the user to simply register a callback function, as is customary for libraries, that matches the signature dds_log_write_fn_t. The callback can be registered by passing it to dds_set_log_sink or dds_set_trace_sink. The functions also allow for registering a void * that will be passed along on every invocation of the the callback. To unregister a log or trace sink, call the respective function and pass NULL for the callback. This will cause Cyclone DDS to reinstate the default handler. aka stdout, stderr, or the file specified in the configuration file.

Log_example

This example is based on the Helloworld example modification, only modifying the code of publisher. c. Also modified the executable file name of cmakelist

//publisher.c

Only with the Verbosity value set in the dds_set_log_mask, such logs will be recorded when calling the callback function.

# Set the logging for this application

dds_set_log_mask(DDS_LC_ERROR | DDS_LC_WARNING | DDS_LC_INFO);

DDS configuration.xml file

#open QEMU_LINUX

DDS_work_space/qemu_folder/qemu$ ./qemu_x86-64-linux.sh

# command.log 这个文件里包含了一些使用的命令

root@QEMU_LINUX:/opt/vrte/eclipse_cyclonedds# cat command.log

#Download file from/to target on host 

scp -P 2210 ./Log_Publisher root@127.0.0.1:/opt/vrte/eclipse_cyclonedds

#Run dds example 

cd /opt/vrte/eclipse_cyclonedds

# set CYCLONEDDS_URI

export CYCLONEDDS_URI=file:///opt/vrte/eclipse_cyclonedds/log/configuration.xm  

# set LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/opt/vrte/eclipse_cyclonedds/lib 

./Log_Publisher

#SSH login from host 

ssh root@127.0.0.1 -p 2210

export LD_LIBRARY_PATH=/opt/vrte/eclipse_cyclonedds/lib 

./Log_Subscriber 

 

#SSH login from host 

ssh root@127.0.0.1 -p 2210

cd /opt/vrte/eclipse_cyclonedds/log

touch cyclonedds.log configuration.xml cyclonedds_packet_capture.pcap

Store logs in different log files

The Log_Punlisher application logs will be stored by the callback function into the cyclonedds.log file

Other programs and some initialization information will be stored in cyclonedds.log.PID file.

cat cyclonedds.log.1708

Store all logs in one file

If you want to write all the logs to the cyclonedds. log file, you can remove the ${CYCLONEDS-PID} in configuration.xml, so that you can see that all the logs are stored in the cyclonedds. log file

# in configuration.xml

<OutputFile>

             /opt/vrte/eclipse_cyclonedds/log/cyclonedds.log

</OutputFile>

#In the code

FILE *log_fp = fopen("/opt/vrte/eclipse_cyclonedds/log/cyclonedds.log", "a");

The cyclonedds_package_capture. pcap file

The cyclonedds_package_capture. pcap file is a Packet Capture (PCAP) file used to store network packets captured from a network interface. These files are usually associated with network analysis and troubleshooting activities.

If you need to view and analyze PCAP files, you can use network analysis tools such as Wireshark. Wireshark is a widely used network protocol analyzer that can open PCAP files and provide an easy-to-understand interface to view and analyze the content of data packets.

more detail info you can see:

[1] Configuration File Reference — Eclipse Cyclone DDS, 0.11.0
[2] Configuration guide — Eclipse Cyclone DDS, 0.11.0

[3]https://github.com/eclipse-cyclonedds/cyclonedds/blob/master/docs/dev/logging.md#log-message-guidelines

  • 12
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aFakeProgramer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值