Application logs and system logs are scattered across different servers, which makes them difficult to search, monitor, and analyze. You can use the LoongCollector (Logtail) data collector to collect text logs from ECS instances, self-managed data centers, or hosts from other cloud providers and send them to Simple Log Service for centralized management and analysis. Two collection modes are supported: continuous collection (real-time incremental collection, suitable for continuous monitoring in production environments) and one-time collection (batch import of static files, suitable for historical data migration).
Choose a collection mode
Scenario | Recommended mode |
Application logs are continuously written and require real-time monitoring and alerting | Continuous collection |
One-time import of historical archived objects | One-time collection |
System or data migration to backfill historical data | One-time collection |
Temporary investigation of historical logs for a specific period | One-time collection |
By default, LoongCollector collects only new (incremental) logs. To collect existing static files, you must use the one-time collection mode.
Scope
Supported operating systems and architectures:
LoongCollector currently supports only Linux systems. For Windows hosts, use Logtail. We recommend using LoongCollector for new data ingestion scenarios.
LoongCollector is a new-generation log collection agent launched by Alibaba Cloud Simple Log Service. It is an upgraded version of Logtail. You only need to install either LoongCollector or Logtail, not both.
Computing resource requirements:
CPU: A minimum of 0.4 cores.
Memory: A minimum of 300 MB.
Recommended usage: To ensure stable operation, we recommend that the actual resource usage of LoongCollector (Logtail) remains below 80% of the limit. Actual usage depends on factors such as collection speed, the number of monitored directories and files, and the extent of sending blockages.
Permission requirements:
If you use a Resource Access Management (RAM) user, you must grant the
AliyunLogFullAccessandAliyunECSFullAccesspermissions. For fine-grained authorization, see Appendix: Custom policies.
Collection configuration workflow
Preparations: Create a project and a Logstore. A project is a resource management unit that isolates logs from different services, and a Logstore is the container used to store these logs.
Configure a machine group (Install LoongCollector): Install LoongCollector based on the server type and add it to a machine group. You can use machine groups to centrally manage collection nodes, distribute configurations, and manage server status.
Create and configure log collection rules:
Global and input configurations: Define the name of the collection configuration and the source and scope of log collection.
Log processing and structuring: Configure processing rules based on the log format.
Multi-line logs: This mode is for log entries that span multiple lines, such as Java exception stacks or Python tracebacks. You can identify each log entry using a start-of-line regular expression and merge consecutive lines of the same log into a single, complete entry.
Structured parsing: Use parsing plug-ins, such as regular expression, separator, or NGINX mode, to extract raw strings into structured key-value pairs. Each field can be independently queried and analyzed.
Data Filtering: Configure collection blacklists and content filtering rules to filter log content, which reduces the transmission and storage of redundant data.
Log categorization: Use topics to flexibly distinguish logs from different services, servers, or path sources.
Query and Analysis Configurations: The system enables the full-text index by default, which supports keyword searches. We recommend enabling a field index to perform precise queries and analyses on structured fields, which improves search efficiency.
Verification and troubleshooting: After you complete the configuration, verify that logs are collected successfully. If you encounter issues such as no data collection, heartbeat failures, or parsing errors, see FAQ.
Preparations
Before you collect logs, you must plan and create a project and a Logstore to manage and store the logs. If you have available resources, you can skip this step and proceed to Configure a machine group (Install LoongCollector).
Create a project
Create a Logstore
Step 1: Configure a machine group (Install LoongCollector)
After you complete the Preparations, install LoongCollector on different types of servers and add them to a machine group.
The following installation steps apply only when the log source is an Alibaba Cloud ECS instance, and the instance and the Simple Log Service project belong to the same Alibaba Cloud account and are in the same region.
If your ECS instance and project are not in the same account or region, or if the log source is a self-managed server, see Install and configure LoongCollector.
Procedure:
On the
Logstores page, click
to the left of the destination Logstore name to expand it.Next to Import Data, click the
icon. In the Quick Data Import dialog box, select a text log ingestion template (such as Single-line Text Log) and click Integrate Now.All text log ingestion templates differ only in their parsing plug-ins. The rest of the configuration process is the same and can be modified later.
On the Machine Group Configurations page, configure the following parameters:
Scenario: Servers
Installation Environment: ECS
Configure Machine Group: Based on the LoongCollector installation status and machine group configuration of the destination server, select the appropriate option:
If LoongCollector is installed and has been added to a machine group, select it from the Source Machine Group list and add it to the Applied Machine Group list. You do not need to create it again.
If LoongCollector is not installed, click Create Machine Group:
The following steps guide you through the automatic installation of LoongCollector and the creation of a machine group.
The system automatically lists ECS instances in the same region as the project. Select one or more instances from which to collect logs.
Click Install and Create as Machine Group. The system automatically installs LoongCollector on the selected ECS instances.
Configure the machine group Name and click OK.
NoteIf the installation fails or remains in a waiting state, check whether the ECS region is the same as the project region.
To add a server with LoongCollector already installed to an existing machine group, see How do I add a server to an existing machine group?
Check heartbeat status: Click Next. The Machine Group Heartbeat Status section appears. Check the Heartbeat status. If it is OK, the machine group connection is normal. Click Next to go to the Logtail configuration page.
If the status is FAIL, it may take some time to establish the initial heartbeat. Wait about two minutes, then refresh the heartbeat status. If it is still FAIL after you refresh, see Machine group heartbeat is FAIL for troubleshooting.
Step 2: Create and configure log collection rules
After you install LoongCollector and configure the machine group, go to the Logtail Configuration page to define log collection and processing rules.
1. Global and input configurations
Define the name of the collection configuration and the source and scope of log collection.
Global Configurations:
Configuration Name: A custom name for the collection configuration. It must be unique within its project. The name cannot be changed after creation. Naming conventions:
Can contain only lowercase letters, digits, hyphens (-), and underscores (_).
Must start and end with a lowercase letter or a digit.
Input Configurations:
Type: Text Log Collection.
File Path: The path of the log file to collect.
Linux: Must start with a forward slash (/). For example,
/data/mylogs/**/*.logindicates all files with the .log extension in the/data/mylogsdirectory.Windows: Must start with a drive letter. For example,
C:\Program Files\Intel\**\*.Log.
Maximum Directory Monitoring Depth: The maximum directory depth that the wildcard character
**in the File Path can match. The default is 0, which means only the current directory is monitored.
2. Log processing and structuring
Configure log processing rules to transform raw, unstructured logs into structured, searchable data. This improves the efficiency of log queries and analysis. We recommend that you add a log sample before you configure the rules:
On the Logtail Configuration page, in the Processor Configurations area, click Add Sample Log and enter the log content to be collected. The system identifies the log format based on the sample and helps generate regular expressions and parsing rules, which simplifies the configuration.
Scenario 1: Handle multi-line logs (such as Java stack traces)
Logs such as Java exception stacks and JSON objects often span multiple lines. In the default collection mode, they are split into multiple incomplete records, which causes a loss of context. To prevent this, you can enable multi-line mode and configure a start-of-line regular expression to merge consecutive lines of the same log into a single, complete entry.
Example:
Raw log without any processing | In default collection mode, each line is treated as an independent log. The stack trace is broken up, and context is lost. | With multi-line mode enabled, a start-of-line regular expression identifies complete logs, preserving the full semantic structure. |
|
|
|
Procedure: On the Logtail Configuration page, in the Processor Configurations area, enable Multi-line Mode:
Type: Select Custom or Multi-line JSON.
Custom: The format of the raw log is not fixed. You must configure a Regex to Match First Line to identify the starting line of each log entry.
Regex to Match First Line: You can generate it automatically or enter it manually. The regular expression must match a complete line of data. For example, the matching regular expression in the preceding example is
\[\d+-\d+-\w+:\d+:\d+,\d+]\s\[\w+]\s.*.Automatic generation: Click Generate Regex Automatically. Then, in the Log Sample text box, select the log content to extract and click Generate Regex.
Manual input: Click Enter Regex Manually. After you enter the expression, click Validate.
Multi-line JSON: When all raw logs are in standard JSON format, Simple Log Service automatically handles line breaks within a single JSON log.
Processing Method If Splitting Fails:
Discard: If a text segment does not match the start-of-line rule, it is discarded.
Retain Single Line: Unmatched text is split and retained in the original single-line mode.
Scenario 2: Structured logging
When raw logs are unstructured or semi-structured text, such as NGINX access logs or application output logs, direct querying and analysis are often inefficient. Simple Log Service provides various data parsing plug-ins that can automatically convert raw logs of different formats into structured data. This provides a solid foundation for subsequent analysis, monitoring, and alerting.
Example:
Raw log without any processing | Log after structured parsing |
| |
Procedure: In the Processor Configurations area of the Logtail Configuration page
Add a parsing plug-in: Click Add Processor and configure a plug-in, such as Regular Expression Parsing, Delimiter Parsing, or JSON Parsing, based on the actual format. This example uses NGINX log collection. Select .
NGINX Log Configuration: Copy the complete
log_formatdefinition from the Nginx server configuration file (nginx.conf) and paste it into this text box.Example:
log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$request_time $request_length ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent"';ImportantThe format definition here must be exactly the same as the format that generates the logs on the server. Otherwise, log parsing fails.
General configuration parameters: The following parameters appear in multiple data parsing plug-ins, and their functions and usage are consistent.
Source Field: Specifies the source field name to be parsed. The default is
content, which is the entire collected log entry.Keep Source Field on Parse Failure: We recommend that you enable this option. If a log cannot be successfully parsed by the plug-in, for example, due to a format mismatch, this option ensures that the original log content is not lost but is fully retained in the specified source field.
Keep Source Field on Parse Success: If you select this option, the original log content is retained even if the log is parsed successfully.
3. Log filtering
During log collection, indiscriminately collecting large amounts of low-value or irrelevant logs, such as DEBUG/INFO level logs, not only wastes storage resources and increases costs but also affects query efficiency and poses data breach risks. To address this, you can implement fine-grained filtering strategies for efficient and secure log collection.
Reduce costs with content filtering
You can filter based on log content fields, such as collecting only logs with a level of WARNING or ERROR.
Example:
Raw log without any processing | Collect only |
| |
Procedure: In the Processor Configurations area of the Logtail Configuration page
Click Add Processor and select :
Field Name: The log field to filter.
Field Value: The regular expression used for filtering. Only full-text matching is supported. Partial keyword matching is not supported.
Control collection scope with a blacklist
You can use a blacklist to exclude specified directories or files, which prevents irrelevant or sensitive logs from being uploaded.
Procedure: On the Logtail Configuration page, in the area, enable Collection Blacklist and click Add.
Supports full matching and wildcard matching for directories and filenames. Only the asterisk (*) and question mark (?) wildcard characters are supported.
File Path Blacklist: The file paths to ignore. Examples:
/home/admin/private*.log: Ignores all files in the/home/admin/directory that start with "private" and end with ".log"./home/admin/private*/*_inner.log: Ignores files ending with "_inner.log" in directories that start with "private" under the/home/admin/directory.
File Blacklist: The filenames to ignore during collection. Example:
app_inner.log: Ignores all files namedapp_inner.log.
Directory Blacklist: The directory path cannot end with a forward slash (/). Examples:
/home/admin/dir1/: The directory blacklist will not take effect./home/admin/dir*: Ignores files in all subdirectories under/home/admin/that start with "dir"./home/admin/*/dir: Ignores all files in subdirectories named "dir" at the second level under the/home/admin/directory. For example, files in the/home/admin/a/dirdirectory are ignored, while files in the/home/admin/a/b/dirdirectory are collected.
4. Log categorization
When multiple applications or instances have logs with the same format but different paths, such as /apps/app-A/run.log and /apps/app-B/run.log, it is difficult to distinguish the source of the collected logs. By configuring topics, you can logically differentiate logs from different applications, services, or paths. This enables efficient categorization and precise querying within a unified storage.
Procedure: In , select a method for generating topics. The following three types are supported:
Machine group topic: When a collection configuration is applied to multiple machine groups, LoongCollector automatically uses the name of the server's machine group as the
__topic__field for upload. This is suitable for scenarios where logs are categorized by host.Custom: The format is
customized://<custom_topic_name>, for example,customized://app-login. This is suitable for static topic scenarios with fixed service identifiers.File path extraction: Extract key information from the full path of the log file to dynamically mark the log source. This is suitable for situations where multiple users or applications share the same log filename but have different paths. When multiple users or services write logs to different top-level directories but the sub-paths and filenames are the same, the source cannot be distinguished by filename alone. For example:
/data/logs ├── userA │ └── serviceA │ └── service.log ├── userB │ └── serviceA │ └── service.log └── userC └── serviceA └── service.logIn this case, you can configure File path extraction and use a regular expression to extract key information from the full path. The matched result is then uploaded to the Logstore as the topic.
File path extraction rule: Based on regular expression capturing groups
When you configure a regular expression, the system automatically determines the output field format based on the number and naming of the capturing groups. The rules are as follows:
In the regular expression for the file path, you need to escape the forward slash (/).
Capturing group type
Scenario
Generated field
Regex example
Matching path example
Generated field example
Single capturing group (only one
(.*?))Only one dimension is needed to distinguish the source (such as username, environment)
Generates the
__topic__field\/logs\/(.*?)\/app\.log/logs/userA/app.log__topic__: userAMultiple non-named capturing groups (multiple
(.*?))Multiple dimensions are needed to distinguish the source, but no semantic tags are required
Generates a tag field
__tag__:__topic_{i}__, where{i}is the ordinal number of the capturing group\/logs\/(.*?)\/(.*?)\/app\.log/logs/userA/svcA/app.log__tag__:__topic_1__userA__tag__:__topic_2__svcAMultiple named capturing groups (using
(?P<name>.*?))Multiple dimensions are needed to distinguish the source, and you want the field meanings to be clear for easy querying and analysis
Generates a tag field
__tag__:{name}\/logs\/(?P<user>.*?)\/(?P<service>.*?)\/app\.log/logs/userA/svcA/app.log__tag__:user:userA;__tag__:service:svcA
5. Output configuration
By default, all logs are sent to the current Logstore, and the compression method is lz4. To distribute logs from the same source to different Logstores, you can configure the following settings:
Multi-target dynamic distribution
Multi-destination delivery is available only for LoongCollector 3.0.0 and later. Logtail does not support this feature.
You can configure up to five output destinations.
After you configure multiple output destinations, this collection configuration is no longer displayed in the collection configuration list of the current Logstore. To view, modify, or delete a multi-destination delivery configuration, see How do I manage multi-destination delivery configurations?.
Procedure: In the Output Configurations area of the Logtail Configuration page.
Click
to expand the output configuration.Click Add Output Targets and complete the following configurations:
Logstores: Select the destination Logstore.
Compression Method: Supports lz4 and zstd.
Route Settings: Route and distribute logs based on their tag fields. Logs that match the routing configuration are uploaded to the destination Logstore. If the routing configuration is empty, all collected logs are uploaded to the destination Logstore.
Tag Name: The name of the tag field used for routing. Enter the field name directly, such as
__path__, without the__tag__:prefix. Tag fields are divided into the following two categories:For more information about tags, see Manage LoongCollector collection tags.
Agent-related: These tags are related to the collection agent itself and do not depend on plug-ins. Examples include
__hostname__and__user_defined_id__.Input plug-in-related: These tags depend on input plug-ins, which provide and enrich the logs with relevant information. Examples include
__path__for file collection, and_pod_name_and_container_name_for Kubernetes collection.
Tag Value: When the tag field value of a log matches this value, the log is sent to this destination Logstore.
Discard this tag?: If you enable this option, the uploaded log does not contain this tag field.
Step 3: Configure query and analysis
After you configure log processing and plug-ins, click Next to go to the Query and Analysis Configurations page:
The system enables the full-text index by default, which lets you perform keyword searches on the original log content.
To perform precise queries by field, wait for the Preview Data to load on the page, then click Automatic Index Generation. Simple Log Service generates a field index based on the first entry in the preview data.
After the configuration is complete, click Next to complete the collection configuration.
Step 4: Verification and troubleshooting
After you complete the configuration, apply it to the machine group and save it. Wait a moment, then verify the configuration using the following checklist.
Verification checklist
Confirm that new content has been added to the log file: LoongCollector collects only incremental logs. Run
tail -f /path/to/your/log/fileand trigger a business operation to ensure that new logs are being written.Check the LoongCollector status:
sudo /etc/init.d/loongcollectord status.Check the machine group heartbeat: Go to the page, click the name of the destination machine group, and in the area, check the Heartbeat status.
If the heartbeat is OK, the machine group is connected to the Simple Log Service project.
If the heartbeat is FAIL, see Machine group heartbeat is FAIL for troubleshooting.
Query logs: Go to the query and analysis page of the destination Logstore, click Search & Analyze (the default time range is the last 15 minutes), and check whether new logs are being ingested.
Troubleshooting common issues
Machine group heartbeat is FAIL
Check the user ID: If your server type is not ECS, or if the ECS instance and the project belong to different Alibaba Cloud accounts, check whether the correct user ID exists in the specified directory. If not, run the following command to create it manually.
Linux: Run the
cd /etc/ilogtail/users/ && touch <uid>command to create a user ID file.Windows: Go to the
C:\LogtailData\users\directory and create an empty file named<uid>.
Check the machine group ID: If you used a custom ID when you created the machine group, check whether the
user_defined_idfile exists in the specified directory. If it exists, check whether the content of the file is consistent with the custom ID configured for the machine group.Linux:
# Configure a custom ID. If the directory does not exist, create it manually. echo "user-defined-1" > /etc/ilogtail/user_defined_idWindows: In the
C:\LogtailDatadirectory, create a new file nameduser_defined_idand write the custom ID into it. If the directory does not exist, create it manually.
If both the user ID and the machine group ID are correctly configured, see Troubleshoot LoongCollector (Logtail) machine group issues for further troubleshooting.
No data is collected
Check for incremental logs: After you configure LoongCollector (Logtail) for collection, if no new logs are added to the log file to be collected, LoongCollector (Logtail) does not collect the file.
Check the machine group heartbeat status: Go to the page, click the name of the destination machine group, and in the area, check the Heartbeat status.
If the heartbeat is OK, the machine group is connected to the Simple Log Service project.
If the heartbeat is FAIL, see Machine group heartbeat is FAIL for troubleshooting.
Confirm that the LoongCollector (Logtail) collection configuration has been applied to the machine group: Even if a LoongCollector (Logtail) collection configuration has been created, logs cannot be collected if it has not been applied to a machine group.
Go to the page, click the name of the destination machine group to go to the Machine Group Configurations page.
On the page, view Manage Configuration. The left side shows All Logtail Configurations, and the right side shows Applied Logtail Configs. If the destination LoongCollector (Logtail) collection configuration has been moved to the applied area on the right, it means the configuration has been successfully applied to the destination machine group.
If the destination LoongCollector (Logtail) collection configuration has not been moved to the applied area on the right, click Modify. In the All Logtail Configurations list on the left, select the destination LoongCollector (Logtail) configuration name, click
to move it to the applied area on the right, and then click OK.
Log collection errors or format errors
Troubleshooting approach: This situation indicates that the network connectivity and basic configuration are normal. The problem is mainly a mismatch between the log content and the parsing rules. You need to view the specific error message to locate the problem:
On the Logtail Configuration page, click the name of the LoongCollector (Logtail) configuration that has a collection error. On the Log Collection Error tab, click Select Time Range to set the query time.
In the area, view the alarm metric of the error log and find the corresponding solution based on Common error types for data collection.
Quotas and limits
Limit | Limitations |
Log entry size | The default limit is 512 KB. You can adjust it using the startup parameter max_read_buffer_size, but it cannot exceed 8 MB. For more information, see Logtail network types, startup parameters, and configuration files. After a multi-line log is split by a start-of-line regular expression, the size limit for each log entry is still 512 KB. If a log exceeds 512 KB, it is forcibly split into multiple entries for collection. For example, if a single log entry is 1025 KB, the first 512 KB is processed, then the next 512 KB, and finally 1 KB. The final collection result is multiple incomplete logs. |
File encoding | Supports UTF-8 or GBK encoded log files. We recommend that you use UTF-8 encoding for better processing performance. Warning If the log file is in another encoding format, issues such as garbled text and data loss may occur. |
Log file rotation | The log rotation queue size is 20 by default. You can adjust it using the startup parameter logreader_max_rotate_queue_size. For more information, see Logtail network types, startup parameters, and configuration files. You can set the collection path to Important Do not mix the two formats in the same Logtail instance. Otherwise, the same file may match multiple Logtail collection configurations, which leads to duplicate collection. If there are more than 20 unprocessed files, newly generated logs are lost. In such cases, first check whether the Logstore shard write quota has been exceeded and adjust the Logtail concurrency level. For more information, see Logtail network types, startup parameters, and configuration files. For more information, see the related technical article. |
Collection behavior when log parsing is blocked | When log parsing is blocked, Logtail keeps the file descriptor for that log file open to prevent the file from being deleted during the block, which would cause data loss. If multiple log file rotations occur during the parsing block, Logtail places the files in the rotation queue. |
Regular expression | Supports Perl Compatible Regular Expressions. |
JSON | Fully supports standard JSON (RFC7159, ECMA-404). Non-standard JSON, such as |
File open behavior | Logtail keeps the collected file and the files in the rotation queue open to ensure data integrity. The file is closed in the following situations:
If you want the file handle to be released within a controllable time after the file is deleted, regardless of whether the file has been fully collected or if logs are still being written to it, you can set a timeout using the startup parameter force_release_deleted_file_fd_timeout. For more information, see Logtail network types, startup parameters, and configuration files. |
Initial log collection behavior | Logtail collects only incremental log files. When a file is first found to be modified, if the file size exceeds 1 MB (512 KB for container standard output), collection starts from the last 1 MB. Otherwise, it starts from the beginning of the file. You can adjust the initial collection size for new files using the tail_size_kb parameter in the Logtail collection configuration. For more information, see Logtail configurations (legacy). If the log file is not modified after the Logtail collection configuration is applied, Logtail does not collect the file. To collect historical files, see Import historical log files. |
Behavior when a file is overwritten | Logtail identifies files using the inode plus the hash of the first 1,024 bytes of the file. If a file is overwritten and either the inode or the hash of the first 1,024 bytes changes, the file is treated as a new file and collected from the beginning. Otherwise, it is not collected. |
Behavior when a file is moved | If a file is moved and it matches a Logtail collection configuration that has never matched this file before, the moved file is treated as a new file and collected from the beginning. Otherwise, it is not collected. |
File collection history | Logtail retains the file collection history progress in memory to ensure that only the incremental part is collected after a file changes. If writes occur to logs outside the retention range, duplicate collection may occur.
|
Non-standard text logs | For lines in logs that contain |
Billing
Installing LoongCollector or Logtail is free of charge.
Fees are incurred for log writing, storage, indexing, querying, transformation, and delivery based on the Logstore's billing method.
If you use the Global Accelerator feature during installation or configuration, additional traffic fees are generated for data transmitted over the accelerated network.
FAQ
How do I manage multi-destination delivery configurations?
Because multi-destination delivery configurations are associated with multiple Logstores, these configurations need to be maintained through the project-level management page:
Log on to the Simple Log Service console and click the name of the destination project.
In the navigation pane on the left, click
. NoteThis page centrally manages all collection configurations under the project, including those that remain after a Logstore was accidentally deleted.
How do I send logs from an ECS server to a project in another Alibaba Cloud account?
If you have not yet installed LoongCollector, see Install the data collector and choose the appropriate cross-account scenario for installation.
If you have already installed LoongCollector, configure a user ID as follows. This ID is used to indicate that this server has permission to be accessed and for its logs to be collected by the account to which the Simple Log Service project belongs.
You need to configure a user ID only when you collect logs from non-account ECS instances, self-managed data centers, or servers from other cloud providers.
Copy the ID of the Alibaba Cloud account to which Simple Log Service belongs: Hover your mouse over the profile picture in the upper-right corner, and view and copy the account ID from the pop-up tab.
Log on to the server from which you want to collect logs and create an Alibaba Cloud account ID file to configure the user ID:
touch /etc/ilogtail/users/{Alibaba Cloud account ID} # If the /etc/ilogtail/users directory does not exist, create it manually. The user ID configuration file only needs the filename, not a file extension.
How do I send logs from an ECS server to a project in a different region under the same account?
If you have not yet installed LoongCollector, see Install the data collector and choose the appropriate cross-region scenario for installation.
If you have already installed LoongCollector, you need to modify the LoongCollector configuration.
Run the
sudo /etc/init.d/ilogtaild stopcommand to stop LoongCollector.Modify the LoongCollector startup configuration file
ilogtail_config.json. Choose one of the following two methods to modify it based on your network requirements:Configuration file path:
/usr/local/ilogtail/ilogtail_config.jsonMethod 1: Use public network transmission
See RegionID and replace the region in the configuration file with the region where Simple Log Service is located. The fields to be modified include the following:
primary_regionThe region part in
config_serversThe
regionand the region part ofendpoint_listindata_servers
Method 2: Use transfer acceleration
Replace the endpoint line in the data_server_list parameter with
log-global.aliyuncs.com. For the file path, see Logtail network types, startup parameters, and configuration files.
Run the
sudo /etc/init.d/ilogtaild startcommand to start LoongCollector.
How do I add a server to an existing machine group?
When you have a configured machine group and want to add a new server, such as a newly deployed ECS instance or a self-managed server, to it to inherit its collection configuration, you can add it by following these steps.
Prerequisites:
A configured machine group already exists.
The new server has LoongCollector installed.
Procedure:
View the destination machine group ID:
On the destination project page, in the navigation pane on the left, click
.On the machine group page, click the name of the destination machine group.
On the machine group configuration page, view the machine group ID.
Perform the corresponding operation based on the ID type:
NoteA single machine group cannot contain both Linux and Windows servers. Do not configure the same custom ID on both Linux and Windows servers. A server can be configured with multiple custom IDs, separated by line feeds.
Type 1: The machine group ID is an IP address
On the server, run the following command to open the
app_info.jsonfile and view theipvalue.cat /usr/local/ilogtail/app_info.jsonOn the destination machine group configuration page, click Modify and enter the server's IP address. Separate multiple IP addresses with line feeds.
After the configuration is complete, click OK and confirm the heartbeat status. After the heartbeat is OK, the server automatically applies the machine group's collection configuration.
If the heartbeat status is FAIL, see Machine group heartbeat is FAIL for further troubleshooting.
Type 2: The machine group ID is a custom ID
Depending on the operating system, write a custom ID string that is consistent with the destination machine group to the specified file:
If the directory does not exist, create it manually. The file path and name are fixed by Simple Log Service and cannot be customized.
Linux: Write the custom string to the
/etc/ilogtail/user_defined_idfile.Windows: Write the custom string to
C:\LogtailData\user_defined_id.
How do I import a collection configuration from another project?
After you complete the Preparations and Machine Group Configuration, you can quickly import a collection configuration from an existing project into the current Logstore to avoid repetitive configuration and improve efficiency.
Procedure:
After you configure the machine group, click Next to go to the Logtail Configuration page.
In the upper-right corner of the page, click Import Other Configuration.
Select the project to import from and the collection configuration under that project.
Click OK. The system automatically loads the selected configuration.
After you check that the imported configuration information is correct, you can click Next to go to the Query and Analysis Configuration page to complete the subsequent configuration.
How do I get a server's IP address to use as a machine group ID?
On a server where LoongCollector (Logtail) is installed, open the /usr/local/ilogtail/app_info.json file and view the ip value.
The server IP address automatically obtained by Logtail is recorded in the ip field of the app_info.json file, as shown below.
If there are multiple servers, manually enter the corresponding IP addresses. IP addresses must be separated by line feeds.
A single machine group cannot contain both Linux and Windows servers. Do not add the IP addresses of both Windows and Linux servers to the same Machine Groups.
How can I have the same log file collected by multiple configurations simultaneously?
By default, to avoid data duplication, Simple Log Service restricts a text log file to be collected by only one Logtail configuration. To enable the same log file to be collected by multiple configurations simultaneously, you need to manually enable the feature that allows a file to be collected multiple times.
Procedure:
When you collect multiple copies, the file read IO, computing resources, and network IO increase linearly.
Log on to the Simple Log Service console and go to the destination project.
In the navigation pane on the left, choose
Logstores and find the destination Logstore.Click
to the left of its name to expand the Logstore.Click Logtail Configuration. In the configuration list, find the destination Logtail configuration and click Manage Logtail Configuration in the Actions column.
On the Logtail configuration page, click Edit:
In , enable Allow File to Be Collected for Multiple Times.
After the configuration is complete, click OK.
Why is the last log entry reported after a long delay? Why is it sometimes truncated?
Cause analysis: Log truncation usually occurs when a log file is missing a line feed at the end, or when a multi-line log, such as an exception stack, has not been completely written. Because the data collector cannot determine whether the log has ended, the last part of the content may be split prematurely or reported with a delay. Different versions of LoongCollector (Logtail) have different handling mechanisms:
Versions before 1.8:
If the last line of a log does not have a line feed (carriage return), or if a multi-line log segment is not finished, the data collector waits for the next write to trigger an output. This can cause the last log entry to be held for a long time without being sent, until a new log is written.Versions 1.8 and later:
A timeout refresh mechanism was introduced to prevent logs from getting stuck. When an unfinished log line is detected, the system starts a timer. After the timeout, the current content is automatically submitted, which ensures that the log is eventually collected.Default timeout: 60 seconds (ensures integrity in most scenarios)
You can adjust this value as needed, but we do not recommend setting it to 0, because this may cause log truncation or loss of some content.
Solution:
You can appropriately extend the waiting time to ensure that the complete log is written before being collected:
Log on to the Simple Log Service console and go to the destination project.
In the navigation pane on the left, choose
Logstores and find the destination Logstore.Click
to the left of its name to expand the Logstore.Click Logtail Configuration. In the configuration list, find the destination Logtail configuration and click Manage Logtail Configuration in the Actions column.
On the Logtail configuration page, click Edit:
In , add the following JSON configuration to customize the timeout period:
{ "FlushTimeoutSecs": 1 }Default value: Determined by the startup parameter
default_reader_flush_timeout(usually a few seconds).Unit: Seconds.
Recommended value: ≥1 second. We do not recommend setting it to 0, because this may cause log truncation or loss of some content.
After the configuration is complete, click OK.
Why does LoongCollector (Logtail) switch from an internal endpoint to a public endpoint during operation? Can it switch back automatically?
During operation, if LoongCollector (Logtail) detects an abnormality in communication with the internal endpoint, such as network failure or connection timeout, the system automatically switches to a public endpoint for data transmission to ensure the continuity and reliability of log collection and avoid log backlog or loss.
LoongCollector: Automatically switches back to the internal network after it recovers.
Logtail: Does not automatically switch back. It must be manually restarted to resume internal network communication.
Appendix: Native parsing plug-ins explained
On the Logtail Configuration page, in the Processor Configurations area, you can add processing plug-ins to structure raw logs. To add a processing plug-in to an existing collection configuration, you can follow these steps:
In the navigation pane on the left, choose
Logstores and find the destination Logstore.Click
to the left of its name to expand the Logstore.Click Logtail Configuration. In the configuration list, find the destination Logtail configuration and click Manage Logtail Configuration in the Actions column.
On the Logtail configuration page, click Edit.
This section introduces only commonly used processing plug-ins that cover common log processing scenarios. For more features, see Extension processing plug-ins.
Rules for combining plug-ins (applies to LoongCollector / Logtail 2.0 and later):
Native and extension processing plug-ins can be used independently or in combination as needed.
We recommend that you use native processing plug-ins first, because they offer better performance and higher stability.
When native features cannot meet business requirements, you can add extension processing plug-ins after the configured native ones to perform supplementary processing.
Order constraint:
All plug-ins are executed sequentially in the order they are configured, which forms a processing chain. Note: All native processing plug-ins must precede any extension processing plug-ins. After you add any extension processing plug-in, you cannot add more native processing plug-ins.
Regular expression parsing
Extract log fields using regular expressions and parse the logs into key-value pairs. Each field can be independently queried and analyzed.
Example:
Raw log without any processing | Using the regular expression parsing plug-in |
| |
Procedure: On the Logtail Configuration page, in the Processor Configurations area, click Add Processor and select :
Regular Expression: Used to match logs. You can generate it automatically or enter it manually:
Automatic generation:
Click Generate Regex Automatically.
In the Log Sample, select the log content to extract.
Click Generate Regex.

Manual input: Enter Regex Manually based on the log format.
After the configuration is complete, click Validate to test whether the regular expression can correctly parse the log content.
Extracted Field: Set the corresponding field name (Key) for the extracted log content (Value).
For other parameters, see the general configuration parameter description in Scenario 2: Structured logging.
Delimiter parsing
Structure log content using a separator, which parses it into multiple key-value pairs. Supports single-character and multi-character separators.
Example:
Raw log without any processing | Split fields by the specified character |
| |
Procedure: On the Logtail Configuration page, in the Processor Configurations area, click Add Processor and select :
Delimiter: Specify the character used to split the log content.
Example: For a CSV file, select Custom and enter a comma (,).
Quote: When a field value contains the separator, you need to specify a quote to enclose the field to avoid incorrect splitting.
Extracted Field: Set the corresponding field name (Key) for each column in order of separation. The rules are as follows:
Field names can contain only letters, digits, and underscores (_).
Must start with a letter or an underscore (_).
Maximum length: 128 bytes.
For other parameters, see the general configuration parameter description in Scenario 2: Structured logging.
Standard JSON parsing
Structures an object-type JSON log, which parses it into key-value pairs.
Example:
Raw log without any processing | Automatic extraction of standard JSON key-values |
| |
Procedure: On the Logtail Configuration page, in the Processor Configurations area, click Add Processor and select :
Original Field: The default value is content. This field is used to store the raw log content to be parsed.
For other parameters, see the general configuration parameter description in Scenario 2: Structured logging.
Nested JSON parsing
Parses nested JSON logs into key-value pairs by specifying the expansion depth.
Example:
Raw log without any processing | Expansion depth: 0, using expansion depth as a prefix | Expansion depth: 1, using expansion depth as a prefix |
| | |
Procedure: On the Logtail Configuration page, in the Processor Configurations area, click Add Processor and select :
Original Field: The name of the source field to be expanded, for example,
content.JSON Expansion Depth: The expansion level of the JSON object. 0 means fully expanded (default), 1 means the current level, and so on.
Character to Concatenate Expanded Keys: The separator for field names during JSON expansion. The default is an underscore _.
Name Prefix of Expanded Keys: Specify the prefix for field names after JSON expansion.
Expand Array: Enable this to expand an array into key-value pairs with indexes.
Example:
{"k":["a","b"]}expands to{"k[0]":"a","k[1]":"b"}.To rename the expanded fields, for example, from prefix_s_key_k1 to new_field_name, you can add a Rename Fields plug-in afterward to complete the mapping.
For other parameters, see the general configuration parameter description in Scenario 2: Structured logging.
JSON array parsing
Use the json_extract function to extract JSON objects from a JSON array.
Example:
Raw log without any processing | Extract JSON array structure |
| |
Procedure: On the Logtail Configuration page, in the Processor Configurations area, switch the Processing Method to SPL, configure the SPL Statement, and use the json_extract function to extract JSON objects from the JSON array.
Example: Extract elements from the JSON array in the log field content and store the results in new fields json1 and json2.
* | extend json1 = json_extract(content, '$[0]'), json2 = json_extract(content, '$[1]')Apache log parsing
Structures the log content based on the definition in the Apache log configuration file, which parses it into multiple key-value pairs.
Example:
Raw log without any processing | Apache Common Log Format |
| |
Procedure: On the Logtail Configuration page, in the Processor Configurations area, click Add Processor and select :
Log Format: combined.
APACHE LogFormat Configuration: The system automatically fills in the configuration based on the Log Format.
ImportantBe sure to verify the auto-filled content to ensure it is exactly the same as the LogFormat defined in your server's Apache configuration file, which is usually located at /etc/apache2/apache2.conf.
For other parameters, see the general configuration parameter description in Scenario 2: Structured logging.
IIS log parsing
Structures the log content based on the IIS log format definition, which parses it into multiple key-value pairs.
Comparison example:
Raw log | Microsoft IIS server-specific format adaptation |
| |
Procedure: On the Logtail Configuration page, in the Processor Configurations area, click Add Processor and select :
Log Format: Select the log format used by your IIS server logs.
IIS: IIS log file format.
NCSA: NCSA Common Log Format.
W3C: W3C Extended Log File Format.
IIS Configuration Fields: When you select IIS or NCSA, Simple Log Service sets the IIS configuration field by default. When you select W3C, set it to the content of the
logExtFileFlagsparameter in your IIS configuration file. For example:logExtFileFlags="Date, Time, ClientIP, UserName, SiteName, ComputerName, ServerIP, Method, UriStem, UriQuery, HttpStatus, Win32Status, BytesSent, BytesRecv, TimeTaken, ServerPort, UserAgent, Cookie, Referer, ProtocolVersion, Host, HttpSubStatus"
For other parameters, see the general configuration parameter description in Scenario 2: Structured logging.
Data masking
Mask sensitive data in logs.
Example:
Raw log without any processing | Masking result |
| |
Procedure: On the Logtail Configuration page, in the Processor Configurations area, click Add Processor and select :
Original Field: The source field that contains the log content before parsing.
Data Masking Method:
const: Replaces sensitive content with the specified string.
md5: Replaces sensitive content with its corresponding MD5 hash.
Replacement String: When you select const for Data Masking Method, you need to enter a string to replace the sensitive content.
Content Expression that Precedes Replaced Content: Used to find sensitive content. Configure using RE2 syntax.
Content Expression to Match Replaced Content: The expression for the sensitive content. Configure using RE2 syntax.
Time parsing
Parses the time field in the log and sets the parsing result as the log's __time__ field.
Example:
Raw log without any processing | Time parsing |
|
|
Procedure: On the Logtail Configuration page, in the Processor Configurations area, click Add Processor and select :
Original Field: The source field that contains the log content before parsing.
Time Format: Set the corresponding time format based on the time content in the log.
Time Zone: Select the time zone of the log time field. By default, the machine time zone is used, which is the time zone of the environment where the LoongCollector (Logtail) process is running.
Appendix: Access policy reference
Alibaba Cloud account logon: An Alibaba Cloud account has all permissions by default and can perform operations directly.
RAM user logon: Requires the Alibaba Cloud account to grant the corresponding access policies.
Custom policies (fine-grained control)
When system policies cannot meet the least privilege principle, you can achieve fine-grained authorization by creating custom policies. The following is an example of an access policy that includes these permissions:
View projects: View the project list and the details of a specified project.
Manage Logstores: Create new Logstores under a project, or modify or delete existing Logstores.
Manage collection configurations: Create, delete, and modify collection configurations.
View logs: Query and analyze data in a specified Logstore under a specified project.
Replace${regionName},${uid},${projectName}, and${logstoreName}with the actual region name, Alibaba Cloud account ID, destination project, and Logstore.
Permission | Corresponding operation | Resource |
Read-only project |
|
|
Get a specified project |
|
|
Manage Logstores |
|
|
Manage LoongCollector (Logtail) data ingestion |
|
|
Query saved searches |
|
|
Query dashboards |
|
|
Query logs in a specified Logstore |
|
|
Permissions to operate ECS |
|
|
Permissions to operate OOS (Optional) Required only when LoongCollector (Logtail) is automatically installed via OOS in the same account and region as the Simple Log Service and ECS instances. |
|
|
System policies
If you use predefined system policies, we recommend that you grant the following permissions:
AliyunLogFullAccess: Permission to manage Simple Log Service.AliyunECSFullAccess: Permission to manage ECS.(Optional)
AliyunOOSFullAccess: Required when you install LoongCollector (Logtail) with one click using OOS.







