Log Management

2023-07-18
No Rating

Overview

The log management function of PSDK supports four types of logs, Debug, Info, Warn and Error, through log output methods such as serial port, terminal or USB; it can be displayed in different colors by using terminal tools that can display log colors, such as Putty, etc. Different types of logs. The log structure output by the payload device developed based on PSDK is as follows: log color starter + system time + module name + log level identifier + log content + log color end character

Basic Concepts

Log identifier

When viewing logs with a debug tool that does not support displaying log colors, the color identifier for the log is displayed.

  • Log color: Different types of logs have different logo colors. Tools such as XShell, SecureCRT, and Putty can display different types of logs in different colors depending on the log level.

  • Log color start identifier:

    • Black: \033[30m, Red: \033[31m, Green: \033[32m
    • Yellow: \033[33m, Blue: \033[34m, Purple: \033[35m
    • Cyan: \033[36m, White: \033[37m
  • Log color end identifier: \033[0m

Log information

  • System time: When the payload device is powered on, the time of the payload device is the system time of the payload device. After the time synchronization between the payload device and the drone is completed, the time of the payload device will be synchronized with the time of the drone (ms).

  • Module name: the name of the PSDK module (the name cannot be modified), the module name of the user print interface is "user".

  • Log content: a single log cannot exceed 500 bytes at most.

  • Log level: The log levels are Debug, Info, Warn and Error from high to low, and the log management function module can print all logs up to the specified level.

    Table 1. Log Level Descriptions

    log levellog contentoutput interfacelog output color
    Debug - 4debug informationUSER_LOG_DEBUGWhite
    Info - 3key informationUSER_LOG_INFOGreen
    Warn - 2warning informationUSER_LOG_WARNYellow
    Error - 1system error informationUSER_LOG_ERRORRed

Using the log management function

To use the PSDK log management function, you need to initialize the log printing interface, set the log level, and implement the log management function by registering the log printing function.

Note: This tutorial takes "Using STM32 to print log information through serial port on RTOS system" as an example to introduce the method and steps of using the log management function.

1. Initialize the serial port and register the log output method

When using PSDK to develop the log management function of the payload device on the RTOS system, it is recommended to use the serial port to print log information.

static T_DjiReturnCode DjiUser_PrintConsole(const uint8_t *data, uint16_t dataLen)
{
    UART_Write(DJI_CONSOLE_UART_NUM, (uint8_t *) data, dataLen);

    return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

UART_Init(DJI_CONSOLE_UART_NUM, DJI_CONSOLE_UART_BAUD);
2. Register the log printing interface

To use the log management function of PSDK, you need to initialize the log printing method printConsole, set the log level to be printed, whether to enable color display and the printing method corresponding to the log, and register it in the payload device control program through DjiLogger_AddConsole() .

Note: The payload device developed with PSDK supports up to 8 log printing methods at the same time.

T_DjiLoggerConsole printConsole = {
    .func = DjiUser_PrintConsole,
    .consoleLevel = DJI_LOGGER_CONSOLE_LOG_LEVEL_INFO,
    .isSupportColor = true,
};

returnCode = DjiLogger_AddConsole(&printConsole);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    printf("add printf console error");
    goto out;
}
3. Output log information

Call the log print function to output log information, and the log output result is shown in Figure 1. Log information.

USER_LOG_ERROR("psdk log console test.");
USER_LOG_WARN("psdk log console test.");
USER_LOG_INFO("psdk log console test.");
USER_LOG_DEBUG("psdk log console test.");

Figure 1. Log information

Note: The level of the log is Info, so the logs of type Info, Warn and Error in the payload device will be output on the terminal, and the log of type Debug will not be printed out.

Log view

  • Linux:

    • Use Grep Consoleopen in new window on Clion IDE to filter log files of payload devices
    • Use the grep command: Execute ./demo_linux_ubuntu | grep 'Info' in the terminal to filter the required log information. For more usage methods, please use man grep to query
  • RTOS: Use serial port viewing tools such as SecureCRT, XShell or Putty to view log information

If you have any comments or confusion about our documentation, you can click here to give feedback and we will get back to you as soon as possible.