This article describes how to quickly use the TLS iOS SDK to implement a basic log collection workflow, including creating a project, creating a log topic, writing logs, and more.
Prerequisites
Before using the TLS iOS SDK, ensure that you have completed the following:
- The TLS iOS SDK has been installed. For detailed steps, see .
- The Volcano Engine API access key has been created and obtained. The access key AccessKey has full permissions for all APIs. We recommend using an IAM user for API operations and routine O&M. Before using an IAM user, the primary account must grant the IAM user permissions for TLS-related resources and operations.
Create related resources
- Initialize the Client instance.
- You can refer to the following sample code to import the TLS iOS SDK and create a TLS Client. It is recommended to dynamically obtain Volcano Engine credentials and other authentication information via environment variables during initialization to avoid data security risks caused by hardcoding the AccessKey.
- You can manage projects using the TLS Client, such as creating and deleting projects. For corresponding parameter settings, refer to CreateProject.
- You will receive a response similar to the following:
- You can manage log topics using the TLS Client, such as creating and deleting log topics. For corresponding parameter settings, refer to CreateTopic.
- You will receive a response similar to the following:
Upload logs via the TLS Client
You can upload logs to a specified log topic using the TLS Client. The relevant sample code is as follows. For parameter settings for uploading logs, refer to PutLogs. After logs are successfully uploaded, you can later view the real-time logs collected on the server in the console, or query the uploaded log data via the SearchLogs API.
Upload logs using the PutLogs V2 API
The process of defining log uploads using Protobuf is rather complicated. In scenarios where performance requirements for the log upload service are not high, you can use the PutLogs V2 interface provided by the TLS iOS SDK. This allows you to upload logs without assembling complex log structures, using only the language's native built-in data structures. Code example:
Upload logs using asynchronous interfaces
To ensure that PutLogs does not block the current thread, you can use the PutLogsAsync and PutLogsV2Async interfaces provided in the TLS iOS SDK.
Tip
The asynchronous interface does not return a Response object, but instead returns an asynchronous task object. You can obtain the response by setting a callback function to parse the task object.
PutLogsAsync sample code
PutLogsV2Async sample code