Log Analysis (SDK for C)
Log Path
The OBS C SDK log path is specified by the LogPath field in OBS.ini. By default, logs are stored in the logs directory at the same level as the directory where the C SDK dynamic library is located. To locate faults, view the run logs in the logs directory. In Linux, the run log file is eSDK-OBS-API-*-C.run.log. In Windows, the run log file is obs-sdk-c.run.log.
The OBS.ini file must be in the same directory as the dynamic library (libeSDKLogAPI.so for Linux and eSDKLogAPI.dll for Windows).
You can also use the set_obs_log_path function to specify the log path in the code. For details, see Configuring SDK Logging (SDK for C).
Log Format
The SDK log format is: Log time|log level|thread ID|log content. The following is an example:
2018-05-15 22:22:54 803| INFO|[140677572568864]|request_perform start
Log Levels
When current logs cannot be used to troubleshoot system faults, you can change the log level to obtain more information. The log levels, from lowest to highest, are DEBUG (0), INFO (1), WARN (2), and ERROR (3). Lower-level logs include all information from higher-level logs. You can obtain the most information in DEBUG (0) logs and the least information in ERROR (3) logs.
Log level description:
- DEBUG (0): Debug level. Logs at this level include all log information. Debugging information is also printed.
- INFO (1): Information level. Logs at this level include WARN- and ERROR-level logs. The OBS API calling process and key information are also printed.
- WARN (2): Warning level. Logs at this level include ERROR-level logs. Key event information (like curl_global_init initialization failure) is also printed.
- ERROR (3): Error level. Only error information is printed.
Method 1: Using the OBS.ini Configuration File
You can modify the OBS.ini file in the same directory as the dynamic library to configure the size, number, and level of logs. The *_Run parameter is the most commonly used configuration item.
;Every line must be less than 1024 [LogConfig] ;Log Size: unit=KB, 10MB = 10KB * 1024 = 10240KB LogSize_Interface=10240 LogSize_Operation=10240 LogSize_Run=10240 ;Log Num LogNum_Interface=10 LogNum_Operation=10 LogNum_Run=10 ;Log level: debug = 0,info = 1,warn = 2,error = 3 LogLevel_Interface=0 LogLevel_Operation=0 LogLevel_Run=0 ;LogFilePermission LogFilePermission=0600 [ProductConfig] ;Product Name sdkname=eSDK-OBS-API-Linux-C [LogPath] ;Log Path is relative to the path of configuration file LogPath=../logs
| Parameter | Description | Example Value |
|---|---|---|
| LogSize_* | Size of a single log file, in KB | 10240 (10 MB) |
| LogNum_* | Number of retained log files | 10 |
| LogLevel_* | Log level. Available options include 0 (DEBUG), 1 (INFO), 2 (WARN), and 3 (ERROR). | 0 |
| LogFilePermission | Log file permission (only for Linux) | 0600 |
| sdkname | Product name. The value is eSDK-OBS-API-Linux-C for Linux and eSDK-OBS-API-Win-C for Windows. | eSDK-OBS-API-Linux-C |
| LogPath | Path for storing logs, which is relative to the OBS.ini file | ../logs |
Method 2: Using Code to Set the Log Path
You can use the set_obs_log_path function to specify the log path in the code. For details, see Configuring SDK Logging (SDK for C). An example is as follows:
// Call this function before obs_initialize.
obs_status ret_status = obs_initialize(OBS_INIT_ALL);
if (OBS_STATUS_OK != ret_status)
{
printf("obs_initialize failed(%s).\n", obs_get_status_name(ret_status));
return -1;
}
// Specify the log path. The SDK will create the OBS.ini file and log files in this path.
ret_status = set_obs_log_path("/var/log/obs_sdk", false);
if (OBS_STATUS_OK != ret_status)
{
printf("set_obs_log_path failed(%s).\n", obs_get_status_name(ret_status));
} Configuring Unicode Paths in Windows
In Windows, if the log path or file path contains full-width characters, you can use the set_file_path_code function to set the file path encoding to Unicode (ANSI_CODE is used by default). After the setting, the file path parameter of the following functions must be set to a byte sequence encoded in UTF-16. Although the parameter type remains const char*, the actual content is the byte representation of wchar_t.
Function declaration:
// Available only for Windows
void set_file_path_code(file_path_code code);
file_path_code get_file_path_code();
typedef enum {
ANSI_CODE = 0, // The file path is encoded using ANSI by default.
UNICODE_CODE = 1 // The file path is encoded using Unicode (UTF-16).
} file_path_code; The method is as follows:
// Call the function before obs_initialize. It is available only for Windows. set_file_path_code(UNICODE_CODE); // ANSI_CODE is used by default. // After the setting, the log_path parameter of set_obs_log_path must be passed as a wide-character encoded path. // For example, convert the wchar_t path to char* and pass it. set_obs_log_path((const char *)L"D:\\Log directory", false);
After the setting, the local file path parameters of the following functions are also affected:
| Affected Function | Description |
|---|---|
| download_file | The downLoad_file and check_point_file members of download_file_config must be passed as wide-character encoded paths. |
| upload_file | The upload_file and check_point_file members of upload_file_config must be passed as wide-character encoded paths. |
| set_obs_log_path | The log_path parameter must be passed as a wide-character encoded path. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot