Simple Log Service (SLS) provides an SDK for different programming languages, such as .NET Core, Java, Python, PHP, Node.js, C, Go, iOS, Android, and C++. The SDK allows you to perform various operations, such as collecting, querying, and analyzing logs.
Usage notes
SLS SDK for different programming languages varies in terms of implementation. However, SLS SDK for different programming languages encapsulates the same operations of SLS API and provides similar features. SLS SDK supports the following features:
Encapsulation of SLS API. SLS SDK implements the underlying API request creation and response parsing. SLS API for different programming languages supports similar operations. This simplifies the switchover between different programming languages. For more information, see API regulations.
Automatic digital signature of API requests. You do not need to specify the digital signature logic of SLS API. This simplifies the use of SLS API. For more information, see Request signatures.
Protocol Buffer-formatted encapsulation of logs. The logs that are collected by SLS are encapsulated in the Protocol Buffer format. You do not need to specify a format. For more information, see Protocol Buffer format.
Log compression by using the method that is defined in SLS API. SLS SDK for several programming languages allows you to specify whether logs can be written to SLS in compression mode. By default, the compression mode is used.
Unified exception handling mechanism. Use SLS SDK to handle exceptions based on the programming language. For more information, see Exception handling.
Support only for synchronous requests.
SLS SDK for different programming languages
The following table provides links to the references and GitHub source code of SLS SDK for different programming languages.
SLS imposes limits on basic resources, such as the number of projects, the number of logstores, the number of shards, and the size of LogItem. Read Limits on basic resources before you use SLS SDK.
After you collect logs to SLS by using SLS SDK, you must configure indexes for the logs. Then, perform various operations such as query, analysis, and transformation on the logs. For more information, see Create indexes and Guide to log query and analysis.
Programming language | References | GitHub source code |
Java | ||
.NET Core | ||
PHP | ||
Python | ||
Node.js | ||
C | ||
Go | ||
iOS | ||
Android | ||
C++ | ||
HarmonyOS |
Examples
For more information about the examples, see List projects.
FAQs
What features does SLS SDK support?
SLS SDK supports most features of SLS. For example, use SLS SDK to collect, index, query, analyze, transform, consume, and ship logs. You can also configure alerts for logs and manage Scheduled SQL jobs. If you identify a feature that is not supported when you use SLS SDK, we recommend that you update SLS SDK to the latest version and try again or pay attention to subsequent SDK version updates.
How do I use SLS SDK?
SLS SDK provides end-to-end log management. Use SLS SDK in the similar manner as you perform operations in the SLS console. Perform the following steps to use SLS SDK:
Activate SLS.
Obtain an AccessKey pair.
Create a project and a logstore.
Collect logs and store the logs to the logstore.
Create indexes for the logs.
Query and analyze the logs and visualize the query and analysis results.
Transform and ship the logs, and configure alerts for the logs.
SLS provides a console in which you can perform operations in an efficient manner. For more information, see Use LoongCollector to collect and analyze ECS text logs.
How do I handle common errors that may occur when I use SLS SDK?
SLS SDK provides error handing logic. The following errors may occur when you use SLS SDK.
Exceptions that are returned by Simple Log Service. This type of exceptions are handled by Simple Log Service SDK. For more information about this type of exceptions, see the description and error codes of each API operation. For more information about the error codes, see Error codes.
Network exceptions that occur when you use Simple Log Service SDK to send requests. This type of exceptions include network disconnection and server response timeout.
Exceptions that are generated by Simple Log Service SDK and related to platforms and programming languages, such as, memory overflow.
For more information, see Exception handling.
When you use SLS SDK to perform operations such as log collection, index management, data query and analysis, and data transformation, errors may occur. Handle the errors based on the SLS FAQ. For more information, see FAQs.
Are limits imposed when I use SLS SDK?
Yes, SLS imposes limits on basic resources such as the number of projects, the number of logstores, the number of shards, and the size of LogItem. Read Limits on basic resources before you use SLS SDK.
Where can I find SDK code examples?
SLS provides documents for you to obtain sample code of commonly used operations. For more information, see related SDK documents.
SLS SDK for Java:
SLS SDK for Python:
SLS SDK for various programming languages:
For more information about source code, visit Alibaba Cloud GitHub.
References
Debugging platform for SLS SDK
Alibaba Cloud provides OpenAPI Explorer for you to debug SLS SDK. The platform also provides other SDKs, examples, and related documents. Use OpenAPI Explorer to debug SLS API operations without the need to manually encapsulate or sign requests. For more information, visit OpenAPI Explorer.
SLS CLI
SLS provides the CLI to meet the requirements for automated configurations. For more information, see Overview of SLS CLI.