This topic describes how to configure the LoongCollector (Logtail) collector to incrementally collect text logs from ECS instances, self-managed Linux/Windows servers, and other hosts. If you want to collect full logs, you can import historical logs.
Basic collection configuration: This is required when you configure LoongCollector (Logtail) collection. It defines the core parameters of the collection task to ensure that log data is successfully collected and transmitted to the specified Logstore in the project.
Advanced collection configuration (optional): After completing the basic collection configuration, you can perform operations such as data masking and filtering on log content to meet more refined log collection requirements.
Preparations
Basic collection configuration
After confirming that you meet the prerequisites, you can start the basic configuration. You can also refer to Advanced collection configuration to perform operations such as data masking and filtering on log content to meet more refined log collection requirements.
Log on to the Simple Log Service console, click the project that is used to manage log resources to view the list of Logstores, and click the icon before the name of the Logstore that is used to store logs to expand it. Then, click the
icon next to Data Import, enter Text Log in the search box to search for a template, select a suitable template, and click Access Now:
Simple Log Service provides multiple text log import templates such as regular, single-line, and multi-line templates. These templates differ only in log parsing plugins, with all other configurations being identical. Additionally, you can add or remove log parsing plugins within the templates. You can select a template based on the characteristics of the logs to be collected, or select any text log template and then configure and combine plugins.
Single-line text log collection: Stores the entire log line in the content field (preserving the original text). This is suitable for quickly collecting logs that do not require analysis (such as temporary debugging). It is simple to operate, but when analyzing later, you need to manually extract information through fuzzy searches, which has a high analysis cost.
Other text log collection: Selecting built-in parsing functions (such as Nginx/JSON/regex) based on the log format automatically extracts key fields (such as status=200, method=GET), making queries and analysis more efficient. This is suitable for logs that need frequent long-term analysis. Although parsing rules need to be configured, it significantly reduces the cost of queries and analysis.
Comparison example (using Nginx logs as an example)
Original log: | |
Simple mode (single-line text log) collection result | Parsing plugin (Nginx) parsing result |
|
|
Simple single-line
Regular expression parsing
Delimiter parsing
Standard JSON parsing
Nested JSON parsing
JSON array parsing
Nginx log parsing
IIS log parsing
Apache log parsing
Advanced collection configuration
While performing basic collection configuration, you can also refer to the following operations for advanced configuration to meet more refined log collection requirements, or you can adjust the configuration after completing the basic configuration. The following are common advanced configurations and their functions:
LoongCollector (Logtail) provides processing plugins to further parse raw logs into structured data. Processing plugins are divided into native processing plugins and extended processing plugins. This section covers the use of native processing plugins.
On the target project page, click the
icon to expand the target Logstore, click Logtail Configurations, click Manage Logtail Configuration in the Actions column of the target Logtail configuration, and click Edit on the configuration page.
On the Logtail Configuration page, you can select appropriate operations from the following scenarios to modify the collection configuration rules as needed:
Configure multi-line log collection: When the content of a log (such as exception stack information) occupies multiple lines, you need to enable multi-line mode and configure a first line regular expression to match the starting line of the log. This allows multiple lines to be collected and stored as a single log in Simple Log Service.
Allow file to be collected multiple times: Allow a log file to be collected by multiple LoongCollector (Logtail) configurations.
Configure log topic type: Set different topics for different log streams to better organize and categorize log data, making it easier to manage and retrieve related logs.
Configure collection blacklist: Ignore specified directories or files during collection. You can configure blacklists by file path, file, or directory.
Log data masking: Mask sensitive information in logs before saving them to Simple Log Service.
Log content filtering: When there are many invalid logs in the original logs that do not need to be saved to Simple Log Service, you can use log filtering to remove them.
Specify log time: Allows you to parse the time field from logs and set the result as the
__time__
field.Log compression: If you want to optimize log transmission efficiency, you can configure a compression method. The supported methods are
lz4
andzstd
.
Comparison example (using the data masking plugin as an example)
Original log: | |
JSON text log collection result | Data masking plugin parsing result |
|
|
Configure multi-line log collection
Configure log topic type
Allow file to be collected multiple times
Configure collection blacklist
Log data masking
Log content filtering
Specify log time
Log compression
Troubleshooting text log collection issues
Check if there are incremental logs: After configuring LoongCollector (Logtail) collection, if there are no new logs added to the log file to be collected, LoongCollector (Logtail) will not collect that file.
Check the machine group heartbeat status: Go to the
page, click the target machine group name, and check the Heartbeat status in the section.If the heartbeat is OK, it indicates that the connection between the machine group and the Simple Log Service project is normal.
If the heartbeat is FAIL:
Check the user identifier: If your server type is not ECS, or if you are using an ECS instance that belongs to a different Alibaba Cloud account than the project, check whether the correct user identifier exists in the specified directory according to the following table.
System
Specified directory
Solution
Linux
/etc/ilogtail/users/
Execute the
cd /etc/ilogtail/users/ && touch <uid>
command to create a user identifier file.Windows
C:\LogtailData\users\
Go to the
C:\LogtailData\users\
directory and create an empty file named<uid>
.If the specified directory contains a file named after the ID of the Alibaba Cloud account to which the project belongs, the user identifier is configured correctly.
Check the machine group identifier: If you are using a custom identifier machine group, check whether the
user_defined_id
file exists in the specified directory. If it exists, check whether the content of the file is consistent with the custom identifier configured for the machine group.System
Specified directory
Solution
Linux
/etc/ilogtail/user_defined_id
# Configure a custom identifier, manually create the directory if it does not exist echo "user-defined-1" > /etc/ilogtail/user_defined_id
Windows
C:\LogtailData\user_defined_id
Create a
user_defined_id
file in theC:\LogtailData
directory and write the custom identifier in it. (Manually create the directory if it does not exist)If both the user identifier and machine group identifier are configured correctly, see Troubleshooting for LoongCollector (Logtail) machine group issues for further troubleshooting.
Confirm that the LoongCollector (Logtail) collection configuration has been applied to the machine group: Even if the LoongCollector (Logtail) collection configuration has been created, if it has not been applied to the machine group, logs still cannot be collected.
Go to the
page, click the target machine group name, and go to the Machine Group Configuration page.On the page, check Manage Configurations. The left side shows All Logtail Configurations, and the right side shows Applied Logtail Configurations. If the target LoongCollector (Logtail) collection configuration has been moved to the right side (applied area), it indicates that the configuration has been successfully applied to the target machine group.
If the target LoongCollector (Logtail) collection configuration has not been moved to the right side (applied area), click Modify, select the target LoongCollector (Logtail) configuration name in the All Logtail Configurations list on the left, click
to move it to the right side (applied area), and then click Save.
View collection error information: If the above steps are all normal but logs still cannot be collected, it may be due to configuration errors or log format mismatches.
On the Logtail Configurations page, click the name of the LoongCollector (Logtail) configuration with collection issues, and on the Log Collection Errors tab, click Time Range to set the query time.
- section, check the alert type of the error logs and find the corresponding solution in