All Products
Search
Document Center

Serverless App Engine:Configure log collection to SLS

Last Updated:Jun 21, 2026

Collecting standard output logs or file logs from SAE applications to Simple Log Service (SLS) enables persistent storage and aggregated analysis.

Prerequisites

  • Ensure Simple Log Service is activated. If it is not, log on to the Simple Log Service console and follow the on-screen instructions to activate it.

  • Ensure that each instance in your application has at least 0.25 core CPU and 250 MB of available memory.

Enable log collection

Procedure: 

  1. Create an application

    On the SAE Application List page, select a target region and namespace at the top, and then click Create Application. On the Application Basic Information page, configure the parameters and click Next: Advanced Settings.

    Modify a running application

    Warning

    Redeploying an application restarts it. To avoid unexpected issues such as service interruptions, perform the deployment operation during off-peak hours.

    On the SAE Application List page, select a target region and namespace at the top, and then click the target application ID to open the application details page. In the left-side navigation pane, click Basic Information, and then click Deploy Application in the upper-right corner.

    Modify a stopped application

    On the SAE Application List page, select a target region and namespace at the top, and then click the target application ID to open the application details page. Click Basic Information, and then click Modify Application Configuration.

  2. Expand the Log Settings section and enable SLS Log Service.

Configuration details:

  • Select an SLS resource to store SAE application logs:

    • Create Simple Log Service Resource: The system automatically creates an SLS Project. The Project name is in the format sae-<random_string>.

    • Use Existing Simple Log Service Resources: Select an existing SLS Project. The Project must be in the same region as the application.

  • Log labels: Used to identify and categorize log entries. After you enable Custom Log Labels, select a Type to configure the Key and Value. To configure multiple key-value pairs, click Add.

    • Custom: Enter a Variable Name and Variable Value.

    • Reference Configuration Item: Enter a Variable Name, and then select an existing Configuration Item Name and Key.

    Note

    This feature is currently in invitational preview. If you want to use it, contact the technical team in the DingTalk group (group ID: 32874633) to enable it.

  • Collection Log Type:

    • File Logs (Log Path in Container): Use this option if your application writes logs to a file. In the Log Source field, specify the absolute path of the log file in the container, including the filename. For example: /tmp/cjsc.log. Regular expression matching is supported. For example: /path/to/your/files/*.log.

    • Container Standard Output Logs: Use this option if your application prints logs to standard output. The Log Source is displayed as stdout.log.

    • Click + Add to add multiple records.

    • If you select Use Existing Simple Log Service Resources, you can configure a logstoreName and logtail for each record.

    Important
    • Do not store other important files in the path specified as the Log Source to prevent other files in that directory from being overwritten. For example, if your application's executable files and data are stored in /home/admin/app/ and you set the log storage path to /home/admin/, all directories and files under this path will be overwritten. To avoid this issue, set the log storage path to a dedicated directory such as /home/admin/log/.

    • During a batch or phased release, if you change only the Project or Logstore, logs are still collected to the original destination until all batches finish deploying. This is because SLS does not support collecting logs from the same file to different Projects or Logstores.

Verify the results:

  1. On the SAE Application List page, select a target region and namespace at the top, and then click the target application ID to open the application details page.

  2. Click to view the SLS logs.

  3. In the Actions column, click File Logs to open the corresponding Logstore and view the log details.

Remove prefixes from log content

When you collect container stdout logs, the raw log content includes redundant prefixes. You can use one of the following methods to remove these prefixes.

Method 1: Customize Logtail configuration

Important

This feature works only for Logtail 2.0 and later. If you want to use this feature, contact the technical team in the DingTalk group (group ID: 32874633) to upgrade the Logtail version for your SAE application.

  1. Expand the corresponding Logstore and click Logtail Configurations.

  2. On the Logtail Configurations page, click the target Logtail configuration item.

  3. Click Edit and configure the following settings. Leave the other parameters at their default values.

    1. Expand the Processor Configurations section and set Processing Method If Splitting Fails to Retain Single Line.

    2. Set Processing Method to SPL.

    3. In the SPL Statement field, enter * | extend msg=regexp_replace(content, '(\S{33,36}\s\S+\sF\s)','') | project-away content.

  4. Click Save.

  5. Newly collected logs no longer include the prefix.

Method 2: Redirect standard output

  1. Create an application

    On the SAE Application List page, select a target region and namespace at the top, and then click Create Application. On the Application Basic Information page, configure the parameters and click Next: Advanced Settings.

    Modify a running application

    Warning

    Redeploying an application restarts it. To avoid unexpected issues such as service interruptions, perform the deployment operation during off-peak hours.

    On the SAE Application List page, select a target region and namespace at the top, and then click the target application ID to open the application details page. In the left-side navigation pane, click Basic Information, and then click Deploy Application in the upper-right corner.

    Modify a stopped application

    On the SAE Application List page, select a target region and namespace at the top, and then click the target application ID to open the application details page. Click Basic Information, and then click Modify Application Configuration.

  2. Expand the Startup Command section and configure the startup command to redirect the standard output:

    For an image-based application, append 2>&1 | tee -a /home/admin/log/std.log to the original startup command. The path /home/admin/log/std.log is the log file path, which you can customize.

    For example, if the original startup command in the image is CMD ["./main"], set the startup command to ./main 2>&1 | tee -a /home/admin/log/std.log.

    If the image environment does not support the tee command or if you do not need to view real-time logs in the console, replace 2>&1 | tee -a /home/admin/log/std.log with > /home/admin/log/std.log 2>&1.

  3. Expand the Log Settings section. Set Collection Log Type to File Logs (Log Path in Container) and set Log Source to the log file path, such as /home/admin/log/std.log.

  4. Click OK and wait for the application deployment to complete.

  5. Newly collected logs no longer include the prefix.

Improve Logtail collection performance

In the SAE console, you can set environment variables to configure Logtail startup parameters. Configuring these parameters improves Logtail collection performance and helps resolve bottlenecks that affect log collection, such as large memory usage by log files, high log data traffic, and a high Logtail data sending rate.

In the Environment Variable section, select Custom or Reference Configuration Item, and then enter the Variable Name and Variable Value/Variable Reference. For details, see Set environment variables.

  • Variable naming rules

    Add the sls_ prefix to the Logtail environment variable that you want to configure. For example, if you want to add the Logtail parameter max_read_buffer_size, set the environment variable to sls_max_read_buffer_size. This parameter specifies the maximum size of a single log entry that Logtail can read, which is 524,288 bytes in this example. For more parameters, see Set Logtail startup parameters.

  • Mapping between environment variables and Logtail startup parameters

    For details, see Environment variable descriptions.

Quotas and limits

Each Alibaba Cloud account can create up to 200 Logstores and 50 Projects. Limits on basic SLS resources can affect log collection for SAE applications, leading to issues such as short log retention periods or collection failures. For more usage limits, see Basic resource limits.

Billing

Using Simple Log Service incurs additional charges. For details, see SLS billing.

FAQ

  • Does SAE log collection support log rotation?

    Yes. You can implement log rotation by adding a wildcard to the log file name.

    The supported wildcards for filenames are the asterisk (*) and the question mark (?).

  • No data appears in the SLS console when I view file logs. What should I do?

    By default, SLS queries data from the last 15 minutes. If no data appears in SLS, use Webshell to check if your application has generated log files. For details, see Use Webshell to diagnose an application.

    • If log data exists, join the DingTalk group (group ID: 32874633) and contact a product technical expert for help.

    • If no log data exists, check your application configuration.