Log Service (abbreviated to LOG) is a platform service for log scenarios. You can collect, distribute, ship, and query logs quickly without development, which is applicable to scenarios such as log transfer, monitoring, performance diagnosis, log analysis, and audit. Container Service integrates with Log Service, which allows you to send the application logs to Log Service.
Note: On the cluster management page, click Enable Log Service and click OK in the displayed dialog box. After Log Service is successfully enabled, the log index is created for each automatically created Logstore by using the built-in Resource Access Management (RAM) account. With this feature enabled, you will be charged for the Alibaba Cloud Log Service usage after configuring the following settings. For more information, see Log Service billing method. Make sure you know your log volume to avoid large unexpected costs.
Log on to the Container Service console.
Click Swarm > Clusters in the left-side navigation pane.
Click Manage at the right of the cluster.
Click Enable Log Service in the upper-right corner.
Click OK in the displayed dialog box.
Before enabling Log Service in Container Service, activate the RAM service and Log Service first. Click Activate It to activate the RAM service and Log Service if they are not activated yet.
The created Log Service project is displayed after Log Service is successfully enabled.
Container Service installs the Agent required by Log Service on your machine if this is the first time Log Service is enabled. You can find this application on the Application List page. You can use Log Service after the application is installed successfully.
Log on to the Container Service console.
Click Swarm > Applications in the left-side navigation pane.
Select the cluster from the Cluster list and clear the Hide System Applications check box.
The acslogging application is successfully installed.
The system creates a corresponding project in Alibaba Cloud Log Service. You can view the project in Log Service console. The project name contains the Container Service cluster ID.
Most Docker applications write the logs directly to stdout, now you can do this as well (for the scenarios of writing logs to files, see Use file logs in the following section). After enabling Log Service, stdout logs are automatically collected and sent to Alibaba Cloud Log Service.
The following example creates a WordPress application, which contains two services: WordPress service and MySQL service. Logs are collected to Alibaba Cloud Log Service.
aliyun.log_store_dbstdout: stdout # Collect stdout logs to the dbstdout Logstore.
aliyun.log_ttl_dbstdout: 30 # Set the data retention time for the dbstdout Logstore to 30 days.
In the preceding orchestration file:
aliyun.log_store_dbstdout: stdoutindicates to write the container standard to the Logstore
acslog-wordpress-dbstdout. The label format is
nameis the name of the Alibaba Cloud Log Service Logstore. The actually created Logstore name is
appis the application name.
logpathis the log path in the container.
stdoutis a special
logpath, indicating the standard output.
aliyun.log_ttl_<logstore_name>is used to set the data retention time (in days) for the Logstore. The value range is 1–365. If left empty, logs are kept in the Logstore for two days by default.
Note: The value configured here is the initial configuration value. To modify the data retention time later, modify it in the Log Service console.
You can create an application named
wordpress in the Container Service console by using the preceding orchestration file. After the application is started, you can find the Logstore
acslog-wordpress-dbstdout in the Log Service console, in which stores the logs of application
After deploying an application by using the preceding orchestration file, you can view the collected logs in the Alibaba Cloud Log Service console.
Log on to the Log Service console.
Click the name of the Log Service project that corresponds to the cluster. You can view the Logstore
acs-wordpress-dbstdoutused in the orchestration file.
Click Search at the right of the Logstore to view the logs.
To write the logs directly to files (for example,
/var/log/app.log) instead of stdout, configure as follows:
name is the Logstore name.
/var/log/app.log is the log path in the container.
To output multiple log files to Log Service, configure as follows to put the files under multiple directories:
aliyun.log_store_s3: /data/logs/exception/*.log #Wildcards are supported.
Note: Currently, multiple Logstores cannot correspond to the same log directory. The log files corresponding to the three Logstores s1, s2, and s3 in the preceding example must be under three directories.
You can select whether or not to add timestamp when Docker is collecting logs. Configure timestamp by using the
aliyun.log.timestamp label in Container Service. The timestamp is added by default.