LogCollector collects text logs from servers based on the collection configuration and supports parsing logs in single-line complete regex mode. In single-line complete regex mode, LogCollector extracts log content using the specified regular expressions. This topic describes the steps for creating a single-line complete regex mode collection configuration.
Background information
When LogCollector collects logs in complete regex mode, it uses \n as the line break to mark the end of a log entry and extracts log content (value) using the specified regular expression. You need to specify a custom field name (key) for each value to structure the log data. If you need to process single-line text logs in a structured way, we recommend that you use the single-line complete regex mode.
In single-line complete regex mode, TLS adds the following metadata fields to log data collected by LogCollector and creates indexes for them by default.
Prerequisites
- The server where LogCollector is installed must be able to access port 80 and port 443 on the remote server.
Step 1 Select a log space
- Select the region where torch log service is located from the top navigation bar.
- On the left navigation bar, select Common functions > Log Collection.
- Then on the Log Collection page, in the LogCollector tab, click Create collection configuration.
tip
For the regions below, manually select the log collection mode in the LogCollector tab.
Region: Hong Kong (China), Asia Pacific Southeast (Johor), Asia Pacific Southeast (Jakarta).
- Select project and topic, and then click Next: Select host group.
- The collected log data will be stored in the selected log topic.
Step 2 Select host group
- In the All host groups section, select the specified host group for log collection.
- After confirming the host group in the Selected host group section, click Next Step: Collection rule.
Step 3 Configure collection rule
Configure basic information
- Rule name refers to the name of the LogCollector collection configuration.
- You can also click Import collection rules, and select Source region, Source project, and Source configuration rule to import existing collection configurations into the current one. You only need to specify the collection rule name.
- Select whether to enable Container log collection.
- By default, the container log collection is disabled. If you collect host group logs or collect container logs via Sidecar, keep this setting disabled.
- Enter the Collection path.
- Collection path refers to the directory and filename of the logs. LogCollector matches directories based on the directory part of the collection path and monitors log files in those directories that meet the rules. You can set up to 10 different collection paths.
- You can specify a complete directory and filename for collection path. Besides, collection path supports fuzzy matching via wildcard character.
tip
- By default, a log file can only match one collection configuration and is collected into one log topic. If multiple collection configurations collect the same file, the latest created collection configuration rule applies.
- When the wildcard ** is specified in the log collection path, the path matches multiple directory levels. In this case and only in this case, TLS monitors subdirectories up to 8 levels deep under the specified directory.
- TLS currently supports the following wildcards: asterisk *, double asterisk **, and question mark ?. Only one double asterisk ** can be configured at most.
- Common configuration methods and examples for collection paths are as follows.
- Set collection configuration effectiveness policy.
- When log files under the same collection path are matched by multiple collection configurations, the following policies can be set:
- Set collection path denylist.
After configuring the collection path denylist, TLS skips the specified directories and files when collecting logs through LogCollector. After selecting Enable, set the denylist directories and files as prompted on the page.
tip
- Each collection configuration can set up to 10 denylist collection paths.
- When configuring log paths, if you use wildcards but need to exclude certain directories or files, you need to enter the corresponding full paths or filenames in the denylist to ensure effective filtering. For example, if the collection path is /var/log/project/*.log and you want to exclude all subdirectories under /var/log/project, then the collection path denylist should be set to directory paths, with the configured path /var/log/project/**.
The path types in the collection path denylist support setting as directory path and file path.
- Set the Collection policy.
- The collection policy determines whether LogCollector collects incremental logs or complete logs. By default, it collects increment logs.
tip
If the Increment collection policy is selected, after triggering LogCollector collection, the collection policy can not switch to Full collection policy to collect historical logs of the log.
- Collection mode refers to the LogCollector log file parsing mode. In this case, set this to Single-line complete regex mode.
- Manual configuration: Click Single-line complete regex and set up the following parameters.
- Automatic configuration: Click AI recommended collection mode, and then enter or upload a log sample. TLS will use TLS Copilot to analyze the sample automatically. Once complete, you can fill in the relevant configuration with one click as prompted. The recommended result is for reference only; you need to verify based on your actual needs.
tip
- When using TLS Copilot for the first time, you need to read and agree to the Disclaimer and service usage policies.
- TLS Copilot only supports North China 2 (Beijing), South China 1 (Guangzhou), and East China 2 (Shanghai).
- The additional settings required for single-line complete regex mode are as follows.
- Acquisition point in time: use the system time of the server where LogCollector runs as the log timestamp.
- Custom time: extract the time embedded in the original log as the log timestamp. The related configuration is as follows:
- Select whether to skip files that have not been updated.
- If enabled, LogCollector skips files whose log file update time falls outside your specified time range when collecting data.
- Set whether to enable upload parsing failure log.
- Enable: After enabling, you must also configure the failure log key name. The key name defaults to LogParseFailed. All logs that fail to parse are uploaded to TLS, using the configured failure log key name field as the key and the original log content as the value.
- Disable: Logs that fail to parse are not uploaded to TLS.
Choose whether to enable Plugin configuration.
When collecting text logs via LogCollector, if business logs can not be parsed by regular collection modes like JSON due to complex structures or inconsistent format, use LogCollector plugin for post-collection processing. For more details, see Plugin overview. - Enable Advanced settings.
- Select advanced configurations based on your needs. If you have no special requirements, we recommend that you keep the default configuration.
- Confirm the collection configuration and click Next step: Check index configuration.
Step 4 Check index configuration
- Check index configuration.
- Follow the prompts on the page to set or update the index as needed. You can also click Import existing index configuration to import indexes from other log topics.
- If the index for this log topic is already configured, you can decide whether to update the index based on the log fields parsed by the collection rule.
tip
- You must enable the index to query and analyze the collected log data.
- The updated index settings only apply to new data written afterward. For more instructions and limitations on query and analysis, see Query overview and Analysis Overview.
Next steps
After you create the collection configuration, LogCollector collects logs and saves them to the specified log topic. You can then query and analyze logs in log topic. For specific instructions, see Query and analysis workflow.